| 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. |