• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Per Request

 
Poornima Sharma
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

What is the best approach to implement session per request in hibernate? I found different approach like:-

1. By creating filter we can implement session per httprequest.

2. By using session.getCurrentSession. I found few limitations in this:- If a transaction is committed then the current session is closed and new session is created. But what if the transaction is not committed? will the opened session be closed?

3. Third one i found was implementing threadlocal. As per my understanding it will make one session per thread of execution. But it is unclear as to when and who will close the session and how will the session be created.

Please guide as to what is the best approach in which we can use session per request so that we can effectively implement lazy loading.

Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic