I haven't written it yet, but I'm planning on it soon - just wanted to get some ideas from the group. What do you think about creating a ThreadLocal HibernateSession.java file at the persistence level - and then wrapping it on each level (business layer, web layer) to create sessions for that level. Th reason I need to obtain a session at each level is for unit testing - and when the application is actually used, I would think that all session creation would take place at the web layer.
Does this sound reasonable? Thanks, Matt -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Schnitzer, Jeff Sent: Friday, January 17, 2003 3:39 PM To: [EMAIL PROTECTED] Subject: RE: [Hibernate] Re: Using Hibernate from a ServletFilter I notice that the close() is not in a finally{} block; it could be that an exception is being thrown which bypasses the close(). That ServletFilter seems excessively complicated to me. It also requires that the session be obtained from somewhere that has access to the request attributes. I’ve attached a much simpler filter which stores the session in a ThreadLocal and does not require a façade of the Session interface. Anytime you need a hibernate session associated with a request, just call: Session sess = Persistance.getSession(); Admittedly I haven’t tested it much, but this seems like an apropos time to post it. Enjoy :) Jeff Schnitzer [EMAIL PROTECTED] -----Original Message----- From: Jon Lipsky [mailto:[EMAIL PROTECTED] Sent: Thursday, January 16, 2003 11:43 PM To: 'Paul Snively'; '[EMAIL PROTECTED]' Subject: RE: [Hibernate] Re: Using Hibernate from a ServletFilter Hi Paul, I've never run into anything like this in my environment, but you can set the log level to debug for the servlet filter to make sure that all sessions are being closed. (I've never seen them not be closed, but it certainly could be possible.) Jon... -----Original Message----- From: Gavin King [mailto:[EMAIL PROTECTED] Sent: Friday, January 17, 2003 4:48 AM To: Paul Snively; [EMAIL PROTECTED] Subject: RE: [Hibernate] Re: Using Hibernate from a ServletFilter This exception occurs when (during a flush) Hibernate discovers a new reference to a collection that is currently "owned" by another open Session. You should verify that you are closing all your Sessions. (It is nothing to do with the query itself; Hibernate simply decided that the query required that a flush precede the Query.) -----Original Message----- From: Paul Snively [mailto:[EMAIL PROTECTED] Sent: Friday, 17 January 2003 2:26 PM To: [EMAIL PROTECTED] Subject: [Hibernate] Re: Using Hibernate from a ServletFilter Oops, I spoke too soon. It's actually upon calling Query.list() that I get this exception. Specifically, I retrieve a named query and get the list: Query castQuery = session.getNamedQuery("castQuery"); castQuery.setLong(0, iFilmId.longValue()); List cast = (List)castQuery.list(); So far, when using the ServletFilter, the last line throws an exception every time. Thoughts? Paul Snively wrote: > Jon, > > I got your code via the newsgroup--thanks for posting that! > > Unfortunately, under heavy threading load, I start to see exceptions > in > my logs: "Illegal attempt to associate a collection with two open > sessions" is the message that I get. I should add that I have many lazy > associations, and it's upon resolving them that this issue seems to > arise. Any comments from anyone about using this ServletFilter in a > heavily mutlithreaded context would be most welcome. > > Thanks, > Paul > > > > > ------------------------------------------------------- > This SF.NET email is sponsored by: Thawte.com > Understand how to protect your customers personal information by > implementing SSL on your Apache Web Server. Click here to get our FREE > Thawte Apache > Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en ------------------------------------------------------- This SF.NET email is sponsored by: Thawte.com Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] 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 ********** ------------------------------------------------------- This SF.NET email is sponsored by: Thawte.com Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel ------------------------------------------------------- This SF.NET email is sponsored by: Thawte.com - A 128-bit supercerts will allow you to extend the highest allowed 128 bit encryption to all your clients even if they use browsers that are limited to 40 bit encryption. Get a guide here:http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0030en _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel