HHH-4859 fix NPE on true embedded ids (ie no property) when building the metamodel
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18661 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
d586421cfb
commit
80156b4170
|
@ -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 <X> void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassTypeImpl<X> jpaMappingType) {
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue