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:
parent
0f8a36a269
commit
558fcd635a
|
@ -49,6 +49,7 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
|
|||
}
|
||||
|
||||
private <A> SingularAttribute<X, A> buildIdAttribute(PersistentClass persistentClass) {
|
||||
if ( hasIdentifierProperty ) {
|
||||
final Property identifierProperty = persistentClass.getIdentifierProperty();
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Class<A> idClass = identifierProperty.getType().getReturnedClass();
|
||||
|
@ -62,6 +63,10 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
|
|||
.id()
|
||||
.build();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private <A> SingularAttribute<X, A> buildVersionAttribute(PersistentClass persistentClass) {
|
||||
if ( persistentClass.isVersioned() ) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue