Réda Housni Alaoui (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjExZjlmNzdi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-13980?atlOrigin=eyJpIjoiYjExZj...
) HHH-13980 (
https://hibernate.atlassian.net/browse/HHH-13980?atlOrigin=eyJpIjoiYjExZj...
) NullPointerException in AbstractEntityGraphVisitationStrategy.startingCollectionIndex (
https://hibernate.atlassian.net/browse/HHH-13980?atlOrigin=eyJpIjoiYjExZj...
)
Change By: Réda Housni Alaoui (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Hi,
I have a complex object graph (closed source code) that leads to a NullPointerException
when using a specific EntityGraph. I tried to reproduce with a simple opensource case but
I could not.
I think the solution is to add null guard to attributeNode at
[
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src...]
like this:
{code:java}@Override
public void startingCollectionIndex(final CollectionIndexDefinition indexDefinition) {
AttributeNodeImplementor attributeNode = attributeStack.getCurrent();
GraphImplementor subGraphNode = null;
if ( attributeNode != null ) { // <-- THE FIX IS HERE
Map<Class, Subgraph> subGraphs = attributeNode.getKeySubgraphs();
Class javaType = indexDefinition.getType().getReturnedClass();
if (!subGraphs.isEmpty() && subGraphs.containsKey(javaType)) {
subGraphNode = (GraphImplementor) subGraphs.get(javaType);
}
}
graphStack.push( subGraphNode );
super.startingCollectionIndex( indexDefinition );
}{code}
This solution fix fixes my issue.
I am creating a PR for this. Alas there will be not test :/
Here is the stacktrace:
{code:java}java.lang.NullPointerException: null
at
org.hibernate.loader.plan.build.internal.AbstractEntityGraphVisitationStrategy.startingCollectionIndex(AbstractEntityGraphVisitationStrategy.java:183)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollectionIndex(MetamodelGraphWalker.java:245)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollectionDefinition(MetamodelGraphWalker.java:231)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAssociation(MetamodelGraphWalker.java:206)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributeDefinition(MetamodelGraphWalker.java:178)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:140)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntityDefinition(MetamodelGraphWalker.java:97)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAssociation(MetamodelGraphWalker.java:209)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributeDefinition(MetamodelGraphWalker.java:178)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:140)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntityDefinition(MetamodelGraphWalker.java:97)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAssociation(MetamodelGraphWalker.java:209)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributeDefinition(MetamodelGraphWalker.java:178)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:140)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntityDefinition(MetamodelGraphWalker.java:97)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollectionElements(MetamodelGraphWalker.java:295)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollectionDefinition(MetamodelGraphWalker.java:232)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAssociation(MetamodelGraphWalker.java:206)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributeDefinition(MetamodelGraphWalker.java:178)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:140)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntityDefinition(MetamodelGraphWalker.java:97)
at
org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntity(MetamodelGraphWalker.java:56)
at
org.hibernate.loader.plan.build.spi.MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan(MetamodelDrivenLoadPlanBuilder.java:39)
at
org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.<init>(AbstractLoadPlanBasedEntityLoader.java:94)
at org.hibernate.loader.entity.plan.EntityLoader.<init>(EntityLoader.java:125)
at org.hibernate.loader.entity.plan.EntityLoader.<init>(EntityLoader.java:38)
at
org.hibernate.loader.entity.plan.EntityLoader$Builder.byUniqueKey(EntityLoader.java:90)
at
org.hibernate.loader.entity.plan.EntityLoader$Builder.byPrimaryKey(EntityLoader.java:83)
at
org.hibernate.loader.entity.plan.LegacyBatchingEntityLoaderBuilder$LegacyBatchingEntityLoader.<init>(LegacyBatchingEntityLoaderBuilder.java:88)
at
org.hibernate.loader.entity.plan.LegacyBatchingEntityLoaderBuilder$LegacyBatchingEntityLoader.<init>(LegacyBatchingEntityLoaderBuilder.java:69)
at
org.hibernate.loader.entity.plan.LegacyBatchingEntityLoaderBuilder.buildBatchingLoader(LegacyBatchingEntityLoaderBuilder.java:47)
at
org.hibernate.loader.entity.BatchingEntityLoaderBuilder.buildLoader(BatchingEntityLoaderBuilder.java:100)
at
org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2553)
at
org.hibernate.persister.entity.AbstractEntityPersister.getAppropriateLoader(AbstractEntityPersister.java:4512)
at
org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:4395)
at
org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4386)
at
org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:569)
at
org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:537)
at
org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:208)
at
org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:332)
at
org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:108)
at
org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74)
at
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:113)
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1176)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1165)
at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:194)
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2776)
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2757)
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2713)
at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2757)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3312)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3279)
at jdk.internal.reflect.GeneratedMethodAccessor236.invoke(Unknown Source)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314)
at com.sun.proxy.$Proxy179.find(Unknown Source){code}
(
https://hibernate.atlassian.net/browse/HHH-13980#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-13980#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:84eb093 )