| The following exception is thrown with hibernate-core 5.2.14:
Caused by: java.lang.NullPointerException: null
at org.hibernate.persister.entity.AbstractPropertyMapping.getSuperCollection(AbstractPropertyMapping.java:285)
at org.hibernate.persister.entity.AbstractPropertyMapping.addPropertyPath(AbstractPropertyMapping.java:198)
at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:395)
at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:2300)
at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:2347)
at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:3906)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:563)
The code in question looks like this:
private Collection getSuperCollection(MetadataImplementor metadata, PersistentClass clazz1, PersistentClass commonPersistentClass, String propertyName) {
Class<?> c1 = clazz1.getMappedClass();
Class<?> c2 = commonPersistentClass.getMappedClass();
MappedSuperclass commonMappedSuperclass = null;
while ( !c2.isAssignableFrom( c1 ) ) {
if ( commonPersistentClass == null) {
if ( commonMappedSuperclass.getSuperPersistentClass() == null ) {
commonMappedSuperclass = commonMappedSuperclass.getSuperMappedSuperclass();
commonPersistentClass = null;
}
else {
commonPersistentClass = commonMappedSuperclass.getSuperPersistentClass();
commonMappedSuperclass = null;
}
}
else {
if ( commonPersistentClass.getSuperclass() == null ) {
commonMappedSuperclass = commonPersistentClass.getSuperMappedSuperclass();
commonPersistentClass = null;
}
else {
commonPersistentClass = commonPersistentClass.getSuperclass();
commonMappedSuperclass = null;
}
}
}
while ( c2 != Object.class ) {
if ( commonMappedSuperclass != null ) {
Collection collection = metadata.getCollectionBinding( commonMappedSuperclass.getMappedClass().getName() + "." + propertyName );
if ( collection != null ) {
return collection;
}
if ( commonMappedSuperclass.getSuperPersistentClass() == null ) {
commonMappedSuperclass = commonMappedSuperclass.getSuperMappedSuperclass();
commonPersistentClass = null;
}
else {
commonPersistentClass = commonMappedSuperclass.getSuperPersistentClass();
commonMappedSuperclass = null;
}
}
else {
Collection collection = metadata.getCollectionBinding( commonPersistentClass.getEntityName() + "." + propertyName );
if ( collection != null ) {
return collection;
}
if ( commonPersistentClass.getSuperclass() == null ) {
commonMappedSuperclass = commonPersistentClass.getSuperMappedSuperclass();
commonPersistentClass = null;
}
else {
commonPersistentClass = commonPersistentClass.getSuperclass();
commonMappedSuperclass = null;
}
}
}
return null;
}
/* L285 */ marks the line causing the NullPointerException. Be aware that these two while loops would loop forever in absence of this exception since the variables c1 and c2 are never reassigned and there are no break statements either. |