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.