"LazyInitializationException: Unable to perform requested lazy initialization" when merging a detached entity in Hibernate
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
Issue
-
Enabling bytecode enhancement with
<enableLazyInitialization>true</enableLazyInitialization> -
Using
@LazyToOne(LazyToOneOption.NO_PROXY)on aManyToOneassociation -
When merging a detached entity for which the association has not yet been initialized, encountering
... org.hibernate.LazyInitializationException: Unable to perform requested lazy initialization [my_entity_here] - no session and settings disallow loading outside the Session
Resolution
This issue1 is resolved in This content is not included.EAP 7.2 cumulative patch (CP) 1 and later releases. Production systems should use the latest available cumulative patch.
Root Cause
This is a known defect (Content from hibernate.atlassian.net is not included.HHH-13129).
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.