-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem (bug?) with evict and 2 sessions
PostPosted: Thu May 12, 2005 7:39 am 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hello, using version 2.1.8 I encounter the following problem, which I think it might be a bug:

Code:

public void testSessionEvict() throws Exception {
Session s1 = sessionFactory.openSession();
Session s2 = sessionFactory.openSession();
TargetPortfolio tp = (TargetPortfolio)s1.load(TargetPortfolio.class, new Long(1));
s1.clear();
s2.lock(tp, LockMode.NONE);

I tried with s1.clear() and s1.evict(tp), same result.
If s1.close() is called there is no problem.

The s2.lock() results in:

net.sf.hibernate.LazyInitializationException: Illegally attempted to associate a proxy with two open Sessions
at net.sf.hibernate.proxy.LazyInitializer.setSession(LazyInitializer.java:152)
at net.sf.hibernate.impl.SessionImpl.reassociateProxy(SessionImpl.java:1027)
at net.sf.hibernate.impl.SessionImpl.unproxyAndReassociate(SessionImpl.java:1011)
at net.sf.hibernate.impl.SessionImpl.lock(SessionImpl.java:1709)

Looking in LazyInitializer.setSession() I see:

if ( session!=null && session.isOpen() ) {
//TODO: perhaps this should be some other RuntimeException...
throw new LazyInitializationException("Illegally attempted to associate a proxy with two open Sessions");


Indeed s1 is still open and the session field of the evicted object is not cleared, even when it is detached from s1.

According to the "Hibernate in action" book on page 116 section 4.1.1 an object is detached by session close/clear/evict, no difference is made between these. Now it seems that this is not fully the case.

Should not the object(s) evicted/cleared from the session have their session field put to null?

B.t.w. before people ask why we use multiple sessions: in reality we use multiple threads, a thread is getting objects and passes them to worker threads. Since session is not threadsafe we have to use a different session for each thread. We might constantly close the session in the first thread and then reopen a new one, but I'd rather not.


Regards,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 4:57 am 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hello,

Noone seems to know an answer, so may I conclude that it could be a bug? Should I file a bug report somewhere?


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