Issues

Select view

Select search mode

 
50 of

NPE with Query Cache, Left Join Fetch, Inheritance on Both Sides, and No Association

Description

If Query Caching is enabled, and you’re performing a Query with LEFT JOIN FETCH where both sides of the association use inheritance, it breaks down if the entity being fetched doesn’t exist because of a null concrete descriptor. It works if the entity(s) being fetched do exist.

An example of a query that breaks if query caching is enabled:

NOTE: It only breaks if both the Parent entity and the Child entity use Inheritance. If either entity is concrete, the code uses the default concrete descriptor for the entity being fetched and doesn’t run into this issue. Workarounds are to remove FETCH or disable query caching on the query.

 

I’ve attached a sample project ZIP with ParentOne, ParentTwo, OptionalSubChildOne, and OptionalSubChildTwo that shows the issue in the unit test testBreaksIfNoChildExists.

 

Here is the stack trace that pops up when we hit the issue.

java.lang.NullPointerException: Cannot invoke "org.hibernate.persister.entity.EntityPersister.getSubclassId()" because "data.concreteDescriptor" is null at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKeySubInitializers(EntityInitializerImpl.java:694) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:554) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:453) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:97) at org.hibernate.sql.results.graph.Initializer.resolveKey(Initializer.java:101) at org.hibernate.sql.results.graph.collection.internal.SetInitializer.resolveInstanceSubInitializers(SetInitializer.java:100) at org.hibernate.sql.results.graph.collection.internal.AbstractImmediateCollectionInitializer.resolveInstance(AbstractImmediateCollectionInitializer.java:358) at org.hibernate.sql.results.graph.collection.internal.AbstractImmediateCollectionInitializer.resolveInstance(AbstractImmediateCollectionInitializer.java:42) at org.hibernate.sql.results.graph.Initializer.resolveInstance(Initializer.java:149) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveInstanceSubInitializers(EntityInitializerImpl.java:662) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:589) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:453) at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:97) at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:235) at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:141) at org.hibernate.sql.results.spi.ListResultsConsumer.readUnique(ListResultsConsumer.java:283) at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:195) at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:35) at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:224) at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:102) at org.hibernate.sql.exec.spi.JdbcSelectExecutor.executeQuery(JdbcSelectExecutor.java:91) at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:165) at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$1(ConcreteSqmSelectQueryPlan.java:152) at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:442) at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:362) at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:380) at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:143) at org.hibernate.query.Query.getResultList(Query.java:120)

Attachments

1

Details

Assignee

Reporter

Worked in

Components

Affects versions

Priority

Created 1 hour ago
Updated 1 hour ago

Activity

Show:

Flag notifications