I’m working on updating an established application from Wildfly 33.0.2 to Wildfly 34.0.0 and I’m hitting a hibernate exception on a query which works fine in Wildfly 33.0.2. Looks like Hibernate was updated from 6.4.4.Final to 6.6.1.Final during this time.
The stacktrace looks like this
Caused by: java.lang.AssertionError
at org.hibernate@6.6.1.Final//org.hibernate.engine.internal.StatefulPersistenceContext.claimEntityHolderIfPossible(StatefulPersistenceContext.java:391)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.registerLoadingEntity(EntityInitializerImpl.java:1278)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveEntityInstance(EntityInitializerImpl.java:1232)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveInstance(EntityInitializerImpl.java:960)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveInstance(EntityInitializerImpl.java:96)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.Initializer.resolveInstance(Initializer.java:149)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveInstanceSubInitializers(EntityInitializerImpl.java:659)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:588)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:452)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:96)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:235)
at org.hibernate@6.6.1.Final//org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:141)
at org.hibernate@6.6.1.Final//org.hibernate.internal.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:133)
at org.hibernate@6.6.1.Final//org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:52)
at org.hibernate@6.6.1.Final//org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at deployment.ROOT.war//co.cfly.oss.product.ProductQueries.allWithType(ProductQueries.java:432)
The query it is failing on is a relatively simple JPA criteria query so I’m assuming the issue is more to do with those entity’s already having been loaded into the persistence context by a prior query.
public Map<ProductType, Product> allWithType() {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Product> c = entityManager.getCriteriaBuilder().createQuery(Product.class);
Root<Product> root = c.from(Product.class);
root.fetch(Product_.component, JoinType.INNER);
c.where(builder.isNotNull(root.get(Product_.type)));
return entityManager.createQuery(c).getResultStream().collect(Collectors.toMap(Product::getType, e -> e));
}
I’m going to continue to dig and debug this next week and see if I can come up with a reproducer, but any pointers in the right direction would be appreciated as this is getting deeper into the hibernate internals than I usually venture.