-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: problem with multiple threads - sessions closing early?
PostPosted: Mon Nov 22, 2004 5:58 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
Hibernate version: 2.1.6

Hey guys, I'm running into a strange problem with multiple threads in my Hibernate webapp. Each HttpServletRequest gets its own Session from the shared SessionFactory. When only one thread is active at a time, everything is fine. When two threads are active at the same time, one of them almost inevitably throws a LazyInitializationException while traversing the object graph, saying "no session or session was closed".

I initially thought that perhaps both Sessions were using the same underlying Connection object. However, I've tried no connection pooling, c3p0, proxool, and manually getting a Connection object from DriverManager and calling sessionFactory.openSession(conn), and get the same results every time.

I'm using Oracle 9i and the thin Oracle driver. Has anyone ever seen anything like this? Can anyone suggest avenues of research?

Thanks very much for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 9:31 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
I have a situation same as yours and it occurs occasionally.I ever tried to track the trace,but got nothing about it.When i remove the attribute
lazy="true" in class tag,is works fine.First i'm sure that i have alreay taken the values of PO into a FormBean (because i use struts) and closed the session before View layer is coming,So i always don's know why it is so far.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 9:44 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
Hi, amjn. Like you, I'm using lazy collections, but in my case they must be lazy because otherwise the entire object graph would be loaded into memory and it's way too big for that. My workaround at the moment is to put my controller into a critical section and only allow one thread in at a time, but this is obviously undesirable.

I did note something interesting after I turned on DEBUG logs and poked through them. In a few places, it seemed that hibernate was giving statistics on the number of open prepared statements and resultsets. At least once, the prepared statement count appeared to be -1. I unfortunately cannot produce the exact log line at this time since I don't have Oracle handy at home, but can look into it tomorrow if y'all think that merits attention.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 1:17 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
I've been working on this problem off and on for a week or two now and still haven't resolved the issue. Indeed, it keeps looking more and more like a bug in hibernate itself. Can someone suggest an avenue of research that might help verify or invalidate this hypothesis? Something stupid I might be doing that I have overlooked?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 1:41 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you're right, there must be a bug in hibernate.
In fact you're the first user using hibernate in a multithreaded app... :)
sorry but the bug is of course in your code.

how do you open close a session? servlet filter? show code

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 2:01 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
Naturally, I'm not the first to use hibernate in a multi-threaded app! That does not necessarily mean that hibernate is entirely bug-free in this regard.

Of course, as I'm in the act of posting my code, I see the glaring flaw that had eluded me until now. I thank anthony for his kind kick in the pants, which is exactly what I needed, and will now get some real work done.

Still curious about the prepared statement count apparantly being negative at one point, but I'll dig into that more deeply if it recurs. Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 2:04 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
That does not necessarily mean that hibernate is entirely bug-free in this regard.


friend,
there are many many webapps based on hibernate in production so i can say that hibernate is bug free about this.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 4:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's really easy: as long as there is no code to see (and the initial posting form is not filled out completely), it can never be a bug in Hibernate. We are getting way too many bogus reports these days and it takes too much time. We got that down a little bit now, but it could still be better.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 4:23 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
Might it be helpful if thread creators could close their threads when, as now, they become irrelevant?

I've done the open source project tech support thing before and I don't envy you guys. Overall, y'all do a damn good job.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 4:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Then you know that this thread will only continue if you provide the required information about your questions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.