Problem after upgrading from Hibernate 5.1 to 5.3

Hello everyone,

we have a problem with an application using Hibernate as JPA implementation. On Wildfly 12 with Hibernate 5.1 everything works fine. With Wildfly 15 and the included Hibernate 5.3 version the deployment fails with the following exception:

Caused by: java.lang.ClassCastException: org.hibernate.loader.plan.build.internal.spaces.CompositeQuerySpaceImpl cannot be cast to org.hibernate.loader.plan.spi.EntityQuerySpace
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.addJoins(LoadQueryJoinAndFetchProcessor.java:286)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.renderCollectionJoin(LoadQueryJoinAndFetchProcessor.java:323)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.renderJoin(LoadQueryJoinAndFetchProcessor.java:170)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoin(LoadQueryJoinAndFetchProcessor.java:145)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoins(LoadQueryJoinAndFetchProcessor.java:140)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoin(LoadQueryJoinAndFetchProcessor.java:146)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoins(LoadQueryJoinAndFetchProcessor.java:140)
        at org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoins(LoadQueryJoinAndFetchProcessor.java:121)
        at org.hibernate.loader.plan.exec.internal.AbstractLoadQueryDetails.generate(AbstractLoadQueryDetails.java:181)
        at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails.<init>(EntityLoadQueryDetails.java:85)
        at org.hibernate.loader.plan.exec.internal.BatchingLoadQueryDetailsFactory.makeEntityLoadQueryDetails(BatchingLoadQueryDetailsFactory.java:61)
        at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.<init>(AbstractLoadPlanBasedEntityLoader.java:86)
        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.AbstractBatchingEntityLoaderBuilder.buildNonBatchingLoader(AbstractBatchingEntityLoaderBuilder.java:30)
        at org.hibernate.loader.entity.BatchingEntityLoaderBuilder.buildLoader(BatchingEntityLoaderBuilder.java:59)
        at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2483)
        at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2505)
        at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:4175)
        at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:4151)
        at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:230)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)
        ... 11 more

Can anyone point me in the right direction how to fix this problem?

Best regards

Jens

Try to replicate it with this test case template so we can analyse it.

I think the issue was introduced by https://github.com/hibernate/hibernate-orm/commit/865c159bff91c55bf9dfb708eada681b25dcf5e1 .

Apparently we can have composite spaces here too, not only entity spaces.

We have 5.3.8.Final planned for next week so it would be really nice to get a test case.

@Jens_Pelzetter could you get us a test case based on our test case template soon? I’m pretty sure it should be easy if you extract the model/query causing the exception.

@Jens_Pelzetter any progress on the test case? Thanks.

Hello all,

sorry for the delay. It was not so easy to extract the entities causing the problem. But now I was able to reproduce the problem. Test case is here: https://github.com/jpdigital/hibernate-test-case-templates

The problem seams to be that we have an multiple (?) Embeddables of the same type (?) in the subclasses of a common base class. With Hibernate 5.1 everything works fine, starting with Hibernate 5.2 the expectation occurs. Therefore I think that is is a bug in Hibernate. Or do we do something which once worked but should not work?

Thanks and Best regards

Jens

Hello,

any findings so far? This problem is becoming quite problematic for us. Therefore it found be nice to know if it is a bug in Hibernate or if we are doing something which is not supposed to work… In which case we will have to consider how refactor our entities.

Best regards

Jens

@Jens_Pelzetter Thanks for the test case. I created the HHH-13269 for it. Indeed it worked until 5.2.13. This is a regression due to HHH-11544.

I created this Pull Request which you can follow if you’re interested in this fix.

@vlad: Many thanks for your response. Good to know that we did not use something which was never supposed to work ;-).

I think we can wait until a Hibernate release with your fix is published. In the meantime we will stick with Wildfly 12 and Hibernate 5.1.x

Best regards

Jens