LazyInitializationException: Unable to perform requested lazy initialization ... no session and settings disallow loading outside the Session in Hibernate
Issue
-
When accessing a (
@OneToMany
annotated) lazy association (from anEmployee
entity to a list ofTask
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.