'Detached entity passed to persist' during merge when enableLazyInitialization is set to true

Description

After migrating hibernate from 4.3.11 to 5.1.10 and using the new hibernate-enhance-maven-plugin replacing the deprecated ant bytecode enhancement task, the following happens with an entity with OneToMany association and CascadeType.ALL.

  • enableLazyInitialization set to false and the test passes

  • enableLazyInitialization set to true and the test fails with "Detached entity passed to persist"

App worked fine with 4.3.11 version of hibernate and the old bytecode enhancement with ant task.

I can work around this by removing CascadeType.PERSIST but needs to modify lot of associations and the related service classes for persisting new entity.

From the debugging, I found that a Persist event triggers followed by Merge event when CascadeType.ALL is set on an association and the entities are detached when enableLazyInitialization is set to true.

Please find the test attached.

Attachments

1
  • 23 Oct 2017, 02:10 PM

Web links

Activity

Show:

Sanne Grinovero May 23, 2018 at 5:38 PM

sorry we didn't see your comment earlier.

Yes it will, Gail was working on the backport yesterday: https://github.com/hibernate/hibernate-orm/pull/2294

Mario Martinho Dias April 11, 2018 at 3:40 PM

Will the correction be added to the 5.1 maintenance branch? 5.1.13 still suffers from this.

Vlad Mihalcea November 16, 2017 at 8:36 AM

Applied PR upstream.

Fixed

Details

Assignee

Reporter

Labels

Fix versions

Affects versions

Priority

Created October 23, 2017 at 2:15 PM
Updated December 11, 2018 at 7:55 PM
Resolved November 16, 2017 at 8:36 AM