-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Session.lock() causing recursive exception
PostPosted: Mon Jul 24, 2006 5:57 pm 
Newbie

Joined: Mon Jul 24, 2006 3:21 pm
Posts: 14
I have a class with a getter that returns a collection. Here's a greatly simplified example.

Code:
public class Thing
{
   ...other code...

   private Set contents;
   public Set getContents()
   {
      return contents;
   }
}


In the app I'm working on, the Hibernate session might have been closed, and the collection is lazy loaded, so I have to reassociate my objects with a session before I call getContents(). So I tried to rewrite the getContents() method as follows.

Code:
   public Set getContents()
   {
      Session s = HibernateUtils.getCurrentSession();
      s.lock(this,LockMode.NONE);
      Set c = contents;
      if( !c.isEmpty() )
      {
         // force initialization of the set members
         c.iterator().next();
      }
      HibernateUtils.closeSession();
      return c;
   }


At runtime I seem to get a really deeply nested exception. It almost looks like this causes an infinite loop. Does lock() call the getters on my mapped object? Can anyone recommend a fix?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.