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?