Menu

#311 Open session in View pattern

open
nobody
None
5
2008-06-18
2008-06-18
richard
No

"Open view in session" is a pattern commonly used with Hibernate applications. In this pattern every incoming request opens a new hibernate session and transaction, which is closed when the request completes.

See http://www.hibernate.org/43.html for more details.

Typically this is activated via a servlet interceptor that intercepts the request before it is passed on to the actual servlet. The session is then stored in a threadLocal variable for later access.

Unfortunately storing the session in a threadLocal variable doesnt work with thinwire since the thinwire event processing occurs on another thread.

In the thinwire model the session needs to be stored in the Allication.Local storage variable, which is not available to the servlet interceptor....

My solution would be to fire a special event when thinwire starts the event processing and another event with the processing is complete. The first event could be used to open the hibernate session, and the second could be used to close it....

Discussion

  • richard

    richard - 2008-06-18

    Logged In: YES
    user_id=1707323
    Originator: YES

    I have implemented a solution that works to a certain extent.

    How do I go about submitting it?

     
  • Josh Marcy

    Josh Marcy - 2008-06-23

    Logged In: YES
    user_id=2117444
    Originator: NO

    What we have done is use our DBManager class. This uses the Application.Local variable scheme and we funnel all queries and transactions through a common get() function. This means that we have to handle all commits manually, but it correctly ties the information to the session.

     

Log in to post a comment.