org.hibernate.AssertionFailure: null identifier for collection of role thrown when merging entity with generated id

Description

Calling merge on entity with a 1-to-many fails with org.hibernate.AssertionFailure: null identifier for collection of role. Used to work in 5.x

Reproducer based on hibernate-test-case-templates:

Original reproducer with Quarkus 3 / Hibernate 6:

Baseline with Quarkus 2 / Hibernate 5:

Entities:

 

Calling merge on Book without any BookNotes causes this exception:

Activity

Andrea BorieroJuly 30, 2024 at 11:54 AM

Alex LitovskyMay 30, 2024 at 3:34 AM

right, but Quarkus (and sounds like Spring Boot) instruments the entities in this manner, causing this issue.

Yanming Zhou (quaff@github)May 30, 2024 at 3:17 AM

FYI, the test case passes if you remove @RunWith(BytecodeEnhancerRunner.class)

Alex LitovskyMay 29, 2024 at 6:55 PM
Edited

It looks like Quarkus instruments all entities to implement the following interfaces:

  • org.hibernate.engine.spi.ManagedEntity

  • org.hibernate.engine.spi.PersistentAttributeInterceptable

  • org.hibernate.engine.spi.ExtendedSelfDirtinessTracker

That’s why isPersistentAttributeInterceptable returns true when running in Quarkus, and false otherwise..

I verified that it’s the same behavior in Quarkus 2.x and 3.x. However, it stopped working with Hibernate 6.x.

I updated the reproducer to use QuarkusLikeORMUnitTestCase

Alex LitovskyMay 29, 2024 at 3:26 PM
Edited

I added a test for RESOURCE_LOCAL as well. It works in RESOURCE_LOCAL but not in JTA mode. I can’t really simulate JTA without Quarkus.

Hibernate takes a different path in WrapVisitor.processArrayOrNewCollection

In RESOURCE_LOCAL, the call to isPersistentAttributeInterceptable evaluates to false. In JTA/Quarkus, it evaluates to true, and fails on line 127.

Fixed

Details

Assignee

Reporter

Worked in

Sprint

Fix versions

Affects versions

Priority

Created May 29, 2024 at 12:11 AM
Updated August 6, 2024 at 2:53 PM
Resolved July 30, 2024 at 11:54 AM