diff --git a/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java b/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java index 798ade530a..269d54c12f 100644 --- a/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java +++ b/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java @@ -37,6 +37,8 @@ import javax.persistence.metamodel.IdentifiableType; 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 @@ class MetadataContext { ); } } - 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 void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassTypeImpl jpaMappingType) { diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java index 0cbf16257a..b04dabba19 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java @@ -14,13 +14,17 @@ public class SecondMetadataTest extends TestCase { 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 }; } } diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java new file mode 100644 index 0000000000..78930b2159 --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimpleMedicalHistory.java @@ -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; +} diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java new file mode 100644 index 0000000000..e89753a142 --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SimplePerson.java @@ -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; +}