From: Gavin K. <Gav...@ex...> - 2002-12-04 01:47:19
|
Where are connections coming from? A Hibernate ConnectionProvider? Or an application supplied connection? What guarantees does Maverick make about when / wether discard() will be called? Is it *guaranteed* to be called in the case of an exception, etc? > -----Original Message----- > From: Aapo Laakkonen [mailto:aap...@pr...]=20 > Sent: Thursday, 5 December 2002 12:35 AM > To: hib...@li... > Subject: FW: [Hibernate] Lazy Collections >=20 >=20 > > I had a *really* close look into the possibility > > that Hibernate issues the unclosed session WARNing > > when the session has in fact been closed and I've > > concluded that it doesn't. I am quite certain that > > the problem is that the user is not closing the > > sessions. (In a couple of previous complaints about > > this, that turned out to be the case.) >=20 > Ok it might be my fault (and probably is). Do you see any strange in > this: >=20 > Background: >=20 > - I have extended Maveric Dispatcher so that it loads=20 > Hibernate Session Factory from JNDI and places it in servlet=20 > context. Is that proper thing to do? > - I have abstract controller that every of my maverick=20 > commands extends. > - Abstract controller has 2 methods. getSession() that loads=20 > Session factory from Servlet context and then opens a new=20 > session (if user has already called this.getSession, then it=20 > returns previously opened > session) and places it in class level variable and then=20 > returns it to user. > - User then uses session. > - User does not close session. > - Session is closed in Abstract controller's discard() method=20 > that maverick calls automatically after it has served the=20 > client (e.g. gui is generated). >=20 > The proces goes like this: >=20 > 1. User makes request eg. grid.m that is a maveric command. > 2. Maverick initializes NEW controller (the controller=20 > extends abstract > controller) 3. Then maverick calls execute method. 4. execute=20 > method calls this.getSession.find("whatever") <- lazy=20 > collection 5. execute method returns a string (that is the=20 > view to be rended) 6. Maverick generates a view (view uses=20 > lazy collection) 7. Maverick calls discard (that closes a session) >=20 > The generated HTML (in this case) contains many img tags like this >=20 > <img src=3D"image.m?id=3Dnumber" /> >=20 > So every needed image gets loaded throught Maverick from=20 > database. image.m command opens session as above and after=20 > sending raw data with proper content-type session get's=20 > closed in execute method (Maveric calls discard, but it=20 > doesn't do anything cause session is already closed by=20 > execute command). >=20 > The problem is that I have no idea why Hibernate's=20 > SessionImpl finalize method tries to close connections that I=20 > have already closed (I can output proper log messages when=20 > discard is called). What I have found is that if I don't=20 > close connections in execute method (prior view), then I=20 > sometimes leaves connections open. At least on load testing.=20 > If I don't use lazy collections I do not have this problem. >=20 > > As to the use of finally, cleanup code that *must* > > be executed is *exactly* the role of the finally > > block, as per any Java textbook. And it is > > completely predictable. Method exit cannot occur > > without execution of the finally block. Are you > > sure the redbook wasn't talking about finalize(), > > which *is* unreliable? >=20 > It's quite long time when I read that, and I could have read=20 > it wrong (I checked IBM docs and they all used finally)...=20 > and if I think about it, I agree with you. The errors I get=20 > about unclosed connections, I get them from SessionImpl=20 > finalize(). But problem is not there I think. >=20 > Is it proper to place SessionFactory in servlet context, or=20 > should I always retrieve it from JNDI? I think that JNDI=20 > lookup causes some overhead, so I have put the Session=20 > factory in servlet context. >=20 > When I should use Session.disconnect / reconnect instead open=20 > and close? >=20 > Should I set session to null and should I also check if=20 > session.close returns an open connection? Do I need to close=20 > the connection then manually? Do i need to set connection =3D null? >=20 > Kind Regards > Aapo <b/>ungle Laakkonen >=20 >=20 >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: Microsoft Visual Studio.NET=20 > comprehensive development tool, built to increase your=20 > productivity. Try a free online hosted session at:=20 http://ads.sourceforge.net/cgi-bin/redirect.pl?micr0003en _______________________________________________ hibernate-devel mailing list hib...@li... https://lists.sourceforge.net/lists/listinfo/hibernate-devel ********** CAUTION - Disclaimer ********** This message may contain privileged and confidential information. If you are not the intended recipient of this message (or responsible for delivery of the message to such person) you are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. If you have received this message in error, you should destroy it and kindly notify the sender by reply e-mail. Please advise immediately if you or your employer do not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Expert Information Services Pty Ltd ("The Company") shall be understood as neither given nor endorsed by it. The Company advises that this e-mail and any attached files should be scanned to detect viruses. The Company accepts no liability for loss or damage (whether caused by negligence or not) resulting from the use of any attached files. **EIS******** End of Disclaimer ********** |