Results 1 to 2 of 2

Thread: Saving persistent (lazy) objects in http session

  1. #1
    Join Date
    Jan 2006
    Posts
    1

    Default Saving persistent (lazy) objects in http session

    Hello:

    I am using Spring + Hibernate + Tapestry (as part of Appfuse 1.8.2). I am using Spring's OpenSessionInView filter for Hibernate (defined in web.xml).

    I loaded an object from the database using hibernate (lazy = true), and saved that object in my http session. In future http requests, I manipulate that object (In Tapestry, that objest is saved in the Visit class). However, since the orignal hibernate session gets closed at the end of the first http request cycle, subsequent access to that object, which would trigger any database activity, fails with a message like: "Could not initialize proxy - the owning Session was closed".

    I need to save this object in my http session for future reference. However, this object has reference to other objects which are lazily loaded. What is a recommended method of handling this scenario? Basically, I need a mechanism where I would attach (lock, update) the current hibernate session to an object, which was already loaded by a previous hibernate session. I would like to do this in a transparent way.

    Additional info about my problem can be found here:

    http://www.nabble.com/Transaction-an...4577c2369.html

    Thanks ...

    Shovon

  2. #2
    Join Date
    Dec 2004
    Location
    Bucuresti, Romania
    Posts
    72

    Default

    Hi,

    I would use a SessionReattachFilter that does the following:
    1. reattaches some objects from the HTTP Session to the Hibernate Session before continuing the request chain
    2. deattaches some objects from HTTP Session to the Hibernate Session after the request chain is processed.

    You could configure this through a set of [HTTP Session attribute name -- LockMode] pairs.

    The OpenSessionInView filter should be before this one in the filter chain.

    Alternatively, you could use the Hibernate session per HTTP session strategy, with connect/disconect of the Hibernate session on each request. But this would most likely break the functionality of the existing code.

    I think this issues has come up on some other threads.

    Mircea.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •