LazyInitializationException: Unable to perform requested lazy initialization ... no session and settings disallow loading outside the Session in Hibernate
Issue
-
When accessing a (
@OneToManyannotated) lazy association (from anEmployeeentity to a list ofTaskentities) 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 of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
