Hi there,
I'M using hibernate 2.1.6 in a cocoon-based Webapplication.
We are unlucky to have a User, retrievd by hibernate stored in the cocoon-session. So we have to re-store that user into the hibernateSession of the current request by calling
Code:
lock(currentUser, LockMode.NONE);
. That far everything works.
But now we have some JXSites (kind of JSP) where we have to retrieve several objects provided by an "Action". Some times we then get an error:
ERROR - Failed to lazily initialize a collection - no session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
I know where the Problem is: My Action uses a Cocoon (=> also an Avalon-) Component to create a new hibernateSession for each request. And when cocoon (better avalon) decides that the work is done for that Action it "dispose()"es my Action and the HibernaeSession is closed. But it should last for just a few more seconds to remain opened till that JX-Page has been processed.
Because we are under heavy pressure I did that quick+dirty thing:
I leave the HibernateSession opened and put it into the HttpSession. So it remains opened. If there is another request the first thing i do is to get the HibernateSession from the HTTPSession and close it.
But sometime the user ends her session. And so I get at the console:
unclosed connection
finalizing unclosed session with closed connection
My questions are:
- Does somebody know a better way to this (except closing the HibernateSession inside these JXTemplates - this is unfortunatly impossible)
- Do you think that our way is "dangerous". This means is it critical to have several opened and
unused hibernateSessions which are closed automaticaly by hibernate itself? That one is the most important question for me.
So please tell me whether I have to rebuild everything or if I could take this solution and have to live with these outputs and a bit wasted ressources.
Thanks in advance!
Helge