In Spring with jpa/hibernate, how do I keep a session open to avoid lazy initialization exceptions?

https://www.hibernate.org/43.html

Basically, you have a few options.

-You can use the “open session in view” pattern where you use a filter/interceptor/AOP – style logic to open a session when server side logic begins, and close it when it’s through.

-You could implement conversations spanning several request-response cycles.

A plain old Servlet Filter is the easiest.

Leave a Comment