-->
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: Session returns objects from an old closed session
PostPosted: Tue Jun 29, 2004 7:55 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
Quote:
Failed to lazily initialize a collection - no session or session was closed


I am using a prepared statement to bulk update the db. After processing,
I commit the connection, close the ps, and close the session. For sake of ex, the session obj id is 194. I open a new session, do some similar ps's, closing in the same way. This session is 203. Finally, I open a session, id 282, execute several HQL queries, and most work, except one, which gives the above error. After debugging, found that the failing HQL returns a collection with the session id 194, and it is closed. The named parameters to the suspect HQL derive from the current 282 session. The query uses session 282 and returns a list, but the objects appear from the previous session.

How should I destroy/cleanup after the old session to avoid this?
What is usually the culprit? I've checked for resources disposal, but I must be missing something.
Thanks


Top
 Profile  
 
 Post subject: Logs
PostPosted: Wed Jun 30, 2004 2:11 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
This is the strange part:
Log:
Quote:
13:52:28,035 DEBUG Loader:239 - total objects hydrated: 0
13:52:28,035 DEBUG SessionImpl:3043 - 1 collections were found in result set
13:52:28,035 DEBUG SessionImpl:3061 - collection fully initialized: [Part.prices#785784]
13:52:28,035 DEBUG SessionImpl:3064 - 1 collections initialized
13:52:28,035 DEBUG SessionImpl:3082 - initializing non-lazy collections
13:52:28,045 DEBUG SessionImpl:3227 - collection initialized
13:52:28,065 ERROR LazyInitializationException:25 - 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
...

Error:
Quote:
[SunJDK14ConditionalEventPump] Exception occurred during event dispatching:
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:214)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Bag.size(Bag.java:232)
at Part.getPrice(Part.java:161)

Code inside getPrice() that throws exception:
Code:
for (int i = 0; i < prices.size(); i++) {


Is the collection initialized and still throwing a lazy initialization exception?

What do I need to do to clear the session cache?


Top
 Profile  
 
 Post subject: Solved
PostPosted: Wed Jun 30, 2004 2:33 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
For the record, there was a side-effect in a setter method that caused the strange behaviour.


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.