fix NPE when identifier is not a property

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17260 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2009-08-11 00:53:08 +00:00
parent 0f8a36a269
commit 558fcd635a
1 changed files with 24 additions and 12 deletions

View File

@ -49,18 +49,23 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
}
private <A> SingularAttribute<X, A> buildIdAttribute(PersistentClass persistentClass) {
final Property identifierProperty = persistentClass.getIdentifierProperty();
@SuppressWarnings( "unchecked" )
Class<A> idClass = identifierProperty.getType().getReturnedClass();
final Type<A> attrType = new BasicTypeImpl<A>( 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<A> idClass = identifierProperty.getType().getReturnedClass();
final Type<A> attrType = new BasicTypeImpl<A>( idClass,
identifierProperty.isComposite() ?
PersistenceType.EMBEDDABLE :
PersistenceType.BASIC);
return SingularAttributeImpl.create(this, attrType )
.property(identifierProperty)
//.member( null ) //TODO member
.id()
.build();
}
else {
return null;
}
}
private <A> SingularAttribute<X, A> buildVersionAttribute(PersistentClass persistentClass) {
@ -101,11 +106,16 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
//TODO check that type and id.getJavaType() are related
checkId();
@SuppressWarnings( "unchecked")
final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) id;
return result;
}
private void checkId() {
if ( ! hasSingleIdAttribute() ) throw new IllegalArgumentException("This is an @IdClass");
}
public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
//TODO check that type and version.getJavaType() are related
@SuppressWarnings( "unchecked")
@ -114,6 +124,7 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
}
public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) {
checkId();
//TODO check that type and id.getJavaType() are related
@SuppressWarnings("unchecked")
final SingularAttribute<X, Y> result = ( SingularAttribute<X, Y> ) id;
@ -147,6 +158,7 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
}
public Type<?> getIdType() {
checkId();
return id.getType();
}