diff --git a/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java b/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java index c29b0eb878..c4103ff172 100644 --- a/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java +++ b/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java @@ -49,18 +49,23 @@ public class EntityTypeImpl extends ManagedTypeImpl implements EntityType< } private SingularAttribute buildIdAttribute(PersistentClass persistentClass) { - final Property identifierProperty = persistentClass.getIdentifierProperty(); - @SuppressWarnings( "unchecked" ) - Class idClass = identifierProperty.getType().getReturnedClass(); - final Type attrType = new BasicTypeImpl( idClass, - identifierProperty.isComposite() ? - PersistenceType.EMBEDDABLE : - PersistenceType.BASIC); - return SingularAttributeImpl.create(this, attrType ) - .property(identifierProperty) - //.member( null ) //TODO member - .id() - .build(); + if ( hasIdentifierProperty ) { + final Property identifierProperty = persistentClass.getIdentifierProperty(); + @SuppressWarnings( "unchecked" ) + Class idClass = identifierProperty.getType().getReturnedClass(); + final Type attrType = new BasicTypeImpl( idClass, + identifierProperty.isComposite() ? + PersistenceType.EMBEDDABLE : + PersistenceType.BASIC); + return SingularAttributeImpl.create(this, attrType ) + .property(identifierProperty) + //.member( null ) //TODO member + .id() + .build(); + } + else { + return null; + } } private SingularAttribute buildVersionAttribute(PersistentClass persistentClass) { @@ -101,11 +106,16 @@ public class EntityTypeImpl extends ManagedTypeImpl implements EntityType< public SingularAttribute getId(Class type) { //TODO check that type and id.getJavaType() are related + checkId(); @SuppressWarnings( "unchecked") final SingularAttribute result = ( SingularAttribute ) id; return result; } + private void checkId() { + if ( ! hasSingleIdAttribute() ) throw new IllegalArgumentException("This is an @IdClass"); + } + public SingularAttribute getVersion(Class type) { //TODO check that type and version.getJavaType() are related @SuppressWarnings( "unchecked") @@ -114,6 +124,7 @@ public class EntityTypeImpl extends ManagedTypeImpl implements EntityType< } public SingularAttribute getDeclaredId(Class type) { + checkId(); //TODO check that type and id.getJavaType() are related @SuppressWarnings("unchecked") final SingularAttribute result = ( SingularAttribute ) id; @@ -147,6 +158,7 @@ public class EntityTypeImpl extends ManagedTypeImpl implements EntityType< } public Type getIdType() { + checkId(); return id.getType(); }