-->
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.  [ 3 posts ] 
Author Message
 Post subject: ailed to lazily initialize a collection - no session or sess
PostPosted: Fri Nov 19, 2004 6:02 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 10:59 am
Posts: 47
Hibernate version: 2.1.4

Hello,

I have an app where I see the following error every once in a while:

Code:
2004-11-19 16:01:45,359 FATAL [     ajp-3]                                        ErrLog 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
        at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
        at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:84)
        at net.sf.hibernate.collection.Bag.add(Bag.java:281)

...
...

2004-11-19 16:01:45,360 FATAL [     ajp-3]                                        ErrLog HIBERNATE SESSION: net.sf.hibernate.impl.SessionImpl@126078f
2004-11-19 16:01:45,360 FATAL [     ajp-3]                                        ErrLog HIBERNATE SESSION IS CONNECTED: true



The last part above is from my app - my attempt to see what state the Hibernate Session is in. And this is where I see a conflict. Hibernate is saying that it either has no Session, or that the Session was closed. However, you can see from the above that the Session instance _does_ exist, and it is even connected to the DB (can it be connected but closed somehow?)

This happens so sporadically, so randomly, I don't know how to trace the source of the problem.

Is there something else I can dump or log on the Hibernate level that would let me peek inside Hibernate and see what is going on with the Session in question?

Thanks,
Otis


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 6:12 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
try session.update()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 6:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
This happens so sporadically, so randomly, I don't know how to trace the source of the problem.


you are wrong with session management, remind session is not threadsafe, you must use something like threadlocal pattern with an interceptor (filter for example) to _bind_ it to the httpRequest cycle.

i'm pretty sure you're linking the session to a threadlocal and doing nothing else, by chance 2 successives httprequests may be executed in the same thread... but it may not, and in this case, you have your bug.
In production you will have really big problems.

It may also be something else, use your debugger

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.