Author: epbernard
Date: 2010-01-27 19:00:50 -0500 (Wed, 27 Jan 2010)
New Revision: 18661
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java
Log:
HHH-4859 fix NPE on true embedded ids (ie no property) when building the metamodel
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-01-27
23:59:29 UTC (rev 18660)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-01-28
00:00:50 UTC (rev 18661)
@@ -37,6 +37,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
@@ -221,9 +223,26 @@
);
}
}
- else {
+ else if ( persistentClass.hasIdentifierMapper() ) {
jpaEntityType.getBuilder().applyIdClassAttributes( buildIdClassAttributes(
jpaEntityType, persistentClass ) );
}
+ else {
+ final KeyValue value = persistentClass.getIdentifier();
+ if (value instanceof Component ) {
+ final Component component = ( Component ) value;
+ if ( component.getPropertySpan() > 1 ) {
+ //FIXME we are an Hibernate embedded id (ie not type)
+ }
+ else {
+ //FIXME take care of declared vs non declared property
+ jpaEntityType.getBuilder().applyIdAttribute(
+ attributeFactory.buildIdAttribute(
+ jpaEntityType,
+ (Property) component.getPropertyIterator().next() )
+ );
+ }
+ }
+ }
}
private <X> void applyIdMetadata(MappedSuperclass mappingType,
MappedSuperclassTypeImpl<X> jpaMappingType) {
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java 2010-01-27
23:59:29 UTC (rev 18660)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java 2010-01-28
00:00:50 UTC (rev 18661)
@@ -14,13 +14,17 @@
assertNotNull( emf.getMetamodel() );
assertNotNull( emf.getMetamodel().entity( DeskWithRawType.class ) );
assertNotNull( emf.getMetamodel().entity( EmployeeWithRawType.class ) );
+ assertNotNull( emf.getMetamodel().entity( SimpleMedicalHistory.class ) );
+ assertNotNull( emf.getMetamodel().entity( SimplePerson.class ) );
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
DeskWithRawType.class,
- EmployeeWithRawType.class
+ EmployeeWithRawType.class,
+ SimpleMedicalHistory.class,
+ SimplePerson.class
};
}
}
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java 2010-01-28
00:00:50 UTC (rev 18661)
@@ -0,0 +1,25 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.io.Serializable;
+import java.util.Date;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class SimpleMedicalHistory implements Serializable {
+
+ @Temporal(TemporalType.DATE)
+ Date lastupdate;
+
+ @Id
+ @JoinColumn(name = "FK")
+ @OneToOne
+ SimplePerson patient;
+}
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java 2010-01-28
00:00:50 UTC (rev 18661)
@@ -0,0 +1,13 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class SimplePerson {
+ @Id
+ String ssn;
+}
Show replies by date