LazyInitializationException: Unable to perform requested lazy initialization ... no session and settings disallow loading outside the Session in Hibernate

Solution Verified - Updated -

Issue

  • When accessing a (@OneToMany annotated) lazy association (from an Employee entity to a list of Task entities) an exception is raised

    ... org.hibernate.LazyInitializationException: Unable to perform requested lazy initialization [support.hibernate.entity.Employee.tasks] - no session and settings disallow loading outside the Session
        at org.hibernate.bytecode.enhance.spi.interceptor.Helper.throwLazyInitializationException(Helper.java:165)
        at org.hibernate.bytecode.enhance.spi.interceptor.Helper.performWork(Helper.java:60)
        at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.loadAttribute(LazyAttributeLoadingInterceptor.java:76)
        at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.fetchAttribute(LazyAttributeLoadingInterceptor.java:72)
        at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.intercept(LazyAttributeLoadingInterceptor.java:61)
        at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.readObject(LazyAttributeLoadingInterceptor.java:296)
        at support.hibernate.entity.Employee.$$_hibernate_read_tasks(Employee.java)
        at support.hibernate.entity.Employee.getTasks(Employee.java:49)
        ...
    

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