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) {
|
private <A> SingularAttribute<X, A> buildIdAttribute(PersistentClass persistentClass) {
|
||||||
|
if ( hasIdentifierProperty ) {
|
||||||
final Property identifierProperty = persistentClass.getIdentifierProperty();
|
final Property identifierProperty = persistentClass.getIdentifierProperty();
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
Class<A> idClass = identifierProperty.getType().getReturnedClass();
|
Class<A> idClass = identifierProperty.getType().getReturnedClass();
|
||||||
|
@ -62,6 +63,10 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
|
||||||
.id()
|
.id()
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private <A> SingularAttribute<X, A> buildVersionAttribute(PersistentClass persistentClass) {
|
private <A> SingularAttribute<X, A> buildVersionAttribute(PersistentClass persistentClass) {
|
||||||
if ( persistentClass.isVersioned() ) {
|
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) {
|
public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
|
||||||
//TODO check that type and id.getJavaType() are related
|
//TODO check that type and id.getJavaType() are related
|
||||||
|
checkId();
|
||||||
@SuppressWarnings( "unchecked")
|
@SuppressWarnings( "unchecked")
|
||||||
final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) id;
|
final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) id;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkId() {
|
||||||
|
if ( ! hasSingleIdAttribute() ) throw new IllegalArgumentException("This is an @IdClass");
|
||||||
|
}
|
||||||
|
|
||||||
public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
|
public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
|
||||||
//TODO check that type and version.getJavaType() are related
|
//TODO check that type and version.getJavaType() are related
|
||||||
@SuppressWarnings( "unchecked")
|
@SuppressWarnings( "unchecked")
|
||||||
|
@ -114,6 +124,7 @@ public class EntityTypeImpl<X> extends ManagedTypeImpl<X> implements EntityType<
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) {
|
public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) {
|
||||||
|
checkId();
|
||||||
//TODO check that type and id.getJavaType() are related
|
//TODO check that type and id.getJavaType() are related
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final SingularAttribute<X, Y> result = ( SingularAttribute<X, Y> ) id;
|
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() {
|
public Type<?> getIdType() {
|
||||||
|
checkId();
|
||||||
return id.getType();
|
return id.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue