Software Development & Operating Systems

Notes on Software Development & Operating Systems

How to resolve LazyInitializationException with SpringMVC using JPA with Hibernate

Follow the below steps if you see the org.hibernate.LazyInitializationException being thrown while trying to render your page.

Add a filter to your web.xml file:

<filter>
<filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>