The entity returned by a merge doesn't contain @ManyToMany relation when the collection resides in @Embeddable

Description

Hibernate doesn't store a @ManyToMany relation when the collection resides in @Embeddable. Although the collection is filled, after calling merge(), the collection field of the return value is null.

To see this bug in action, have a look into this repository and execute JPAUnitTestCase::shouldStoreUsersCollection. One can see that Hibernates merges the collection as expected, if it resides directly within an @Entity. But if the collection resides in an @Embeddable the test fails.

The javadoc of the @ManyToMany annotation states

The ManyToMany annotation may be used within an embeddable class contained within an entity class to specify a relationship to a collection of entities. (...)

So this is expected to work.

 

The bug is reproduciable in both Hibernate v5.6 and v6.1.

Activity

Show:
Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created June 23, 2022 at 12:43 PM
Updated August 30, 2022 at 1:18 PM
Resolved August 25, 2022 at 10:31 AM