"LazyInitializationException: Unable to perform requested lazy initialization" when merging a detached entity in Hibernate

Solution Verified - Updated -

Issue

  • Enabling bytecode enhancement with <enableLazyInitialization>true</enableLazyInitialization>
  • Using @LazyToOne(LazyToOneOption.NO_PROXY) on a ManyToOne association
  • 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
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content