From: Jonas V. P. <jvp...@ti...> - 2002-12-03 08:21:08
|
The implementation of the write() method in cirrus.hibernate.collections.= PersistentCollection states: protected final void write() { initialize(true); if ( session!=3Dnull && session.isOpen() ) session.dirty(this); } This means the session needs to be open. Also, the Docs mentions that lazy collections need to have an open sessio= n. Could we safely modify the code to reopen the session when needed? protected final void write() { initialize(true); if ( session !=3D null ) { if ( session.isOpen() ) { session.dirty(this); } else { // Re-open session session.reopen(); // ommitted try-catch session.dirty(this); } } } *************************************************************************= ****** Hou uw internetverbruik beter onder controle ... surf met Tiscali Complet= e ... http://tiscali.complete.be |
From: Aapo L. <aap...@pr...> - 2002-12-03 08:47:41
|
> The implementation of the write() method in > cirrus.hibernate.collections.PersistentCollection > states: > > This means the session needs to be open. > Also, the Docs mentions that lazy collections > need to have an open session. Gavin: I have also other problems with lazy collections. I get WARNings about Unclosed Sessions (finalize method in SessionImpl). I use Maverick Web MVC Framework and it has discard() method in one interface that you can implement. I have put my Session closing code in it, but it doesn't help. It continues to leave sessions open. I have tried almost everything, but I cannot get rid of those Unclosed Sessions. Only solution I have found is closing session before going to a view rendering phase, and that means that lazy initialization is not an option anymore. Also I see that Hibernate uses a lot of finally {} blocks to do some cleaning. If I understand correctly, at least what I have read from some of IBM's whitepapers, they don't recommend you to use finally {} to do a cleaning (mainly they don't recommend to put connection closing code in it) as it cannot be determined when that block gets called. I migth be wrong, but I can get the article if you like (?). Any ideas? Do you want the example code that leaves connections some times open (ie. under load)? For resin users: You should enable... <ignore-client-disconnect>true</ignore-client-disconnect> ... if you don't, you are going to get potential problems. i.e. resin starts executing the code, but meanwhile client disconnects and resin recognices that and then immediately stops code execution (you can demonstrate this by yourself by using e.g. Internet Explorer and then hit a page and push F5 key down for about 15 seconds). What this means in practice is that if you close connections after serving client, then that code never gets executed -> you are going to run out of db connections that you have in some pool (i.e. jndi). I think that this settings should be put in some FAQ. Kind Regards Aapo Laakkonen |
From: Brad C. <bra...@wo...> - 2002-12-03 10:01:00
|
> I have also other problems with lazy collections. I get WARNings about > Unclosed Sessions (finalize method in SessionImpl). I use Maverick Web > MVC Framework and it has discard() method in one interface that you can > implement. I have put my Session closing code in it, but it doesn't > help. It continues to leave sessions open. I have tried almost > everything, but I cannot get rid of those Unclosed Sessions. Only > solution I have found is closing session before going to a view > rendering phase, and that means that lazy initialization is not an > option anymore. on the project i am currently working on we use a servlet filter to open a connection in a try block and stick the close connection in a finally block. we r not having any probs with lazy initialisation or unclosed sessions. however, we r also not using the absolute latest version of hibernate. > Also I see that Hibernate uses a lot of finally {} blocks to do some > cleaning. If I understand correctly, at least what I have read from some > of IBM's whitepapers, they don't recommend you to use finally {} to do a > cleaning (mainly they don't recommend to put connection closing code in > it) as it cannot be determined when that block gets called. I migth be u definitely don't want to rely on finally blocks to clean up connections, sockets, etc. when it can/should be done some other way. however, aren't they the last line of defence when u r relying on someone else to clean up after themselves? for example, only the developer of the client app knows when they r finished with a session and therefore when to close it. regards brad |
From: Max R. A. <ma...@eo...> - 2002-12-03 11:58:55
|
No! If an session has been closed forcefully or by other means, hibernate internals should not reopen the session - at least not per default! If the session has been closed there is a reason for it - one might be to ensure that the ui-layer does not accidently fetches data by "dotting" around in the object graph. If you want the session to be (re)opend - why don't you just keep the session open ? /max ----- Original Message ----- From: "Jonas Van Poucke" <jvp...@ti...> To: "Hibernate Developers" <hib...@li...> Sent: Tuesday, December 03, 2002 9:20 AM Subject: [Hibernate] Lazy Collections The implementation of the write() method in cirrus.hibernate.collections.PersistentCollection states: protected final void write() { initialize(true); if ( session!=null && session.isOpen() ) session.dirty(this); } This means the session needs to be open. Also, the Docs mentions that lazy collections need to have an open session. Could we safely modify the code to reopen the session when needed? protected final void write() { initialize(true); if ( session != null ) { if ( session.isOpen() ) { session.dirty(this); } else { // Re-open session session.reopen(); // ommitted try-catch session.dirty(this); } } } **************************************************************************** *** Hou uw internetverbruik beter onder controle ... surf met Tiscali Complete ... http://tiscali.complete.be ------------------------------------------------------- This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size! http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en _______________________________________________ hibernate-devel mailing list hib...@li... https://lists.sourceforge.net/lists/listinfo/hibernate-devel |