Announcement Announcement Module
Collapse
No announcement yet.
lazy loading across sessions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • lazy loading across sessions

    When i login to my webapp my User object gets loaded using hibernate, i store this Object in my HttpSession, on the resulting webpage show some of the properties of the User object, these get lazyly loaded from the view (thanks to the OpenSessionInViewInterceptor).

    Now when i request another page, thus resulting in a new session (opened by the interceptor). Now there is no problem using the properties that where initially loaded, but when i want to use a property that was not yet loaded the first time i get a "LazyInitializationException - could not initialize proxy - the owning Session was closed."

    Is there a way i can lazily load my User object properties using the newly created session ?

    Or am i tackling this the whole wrong way ... i mean, i wouldnt like to have to just store the id of the User object in my HttpSession and always having to load the User object in every page.

  • #2
    Here's an interesting discussion.

    Comment


    • #3
      thanks for the reply ... so its basicly impossible

      so i ll test what would be the best solution
      1) just store the User id in the HttpSession and load the User object in every page, but have the User object stored in 2nd level cache
      2) unlazy fetching of the whole User object (quite big)

      Comment


      • #4
        Not impossible. Never implemented it myself, but you can find some guide:
        http://www.hibernate.org/43.html#A5
        http://opensource.atlassian.com/conf...on?pageId=1447

        Comment


        • #5
          The alternative is reattaching the entity to the Hibernate Session when you want to lazy load more associations.
          Last edited by karldmoore; Aug 29th, 2007, 11:31 AM.

          Comment


          • #6
            just store the ID, pull it every request but rely on the 2nd level cache. works fine, no trip to the DB.

            Comment


            • #7
              Originally posted by lloyd.mcclendon View Post
              just store the ID, pull it every request but rely on the 2nd level cache. works fine, no trip to the DB.
              That's fine if you aren't making any changes to the entity.
              Last edited by karldmoore; Aug 29th, 2007, 11:31 AM.

              Comment


              • #8
                If that user object is used on every page, it might make sense to eagerly fetch all data when loading the object the first time.

                Simon

                Comment


                • #9
                  Originally posted by sniederb View Post
                  If that user object is used on every page, it might make sense to eagerly fetch all data when loading the object the first time.
                  I think this is typically the easiest way of solving the problem.
                  Last edited by karldmoore; Aug 29th, 2007, 11:31 AM.

                  Comment

                  Working...
                  X