-->
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.  [ 6 posts ] 
Author Message
 Post subject: AssertionFailure: possible nonthreadsafe access to session
PostPosted: Fri Dec 19, 2003 9:54 am 
Beginner
Beginner

Joined: Fri Nov 28, 2003 6:57 am
Posts: 20
Hi,

I'm getting this error in my program and don't know why...

I have a process implementing the Runnable interface which looks this way:

public class PerfectMatcherProcess extends HibernateProcess {

protected final ThreadLocal session = new ThreadLocal();

protected void initSession() throws DataException {
Session s = PersistenceLayer.getInstance().getSession();
session.set(s);
}

protected Session getSession() {
return (Session) session.get();
}

public void run() {
...
initSession();
...
Transaction tx = getSession().beginTransaction();
...
getSession.update(a);
getSession.save(b);
getSession.evict(b);
...
getSession().delete("from X where X.test = 'T'"); // here comes the exception!
...
}
}

a, b and c are objects, X is a classname. If I run my program, I'm getting the following exception:

net.sf.hibernate.AssertionFailure: possible nonthreadsafe access to session
at net.sf.hibernate.impl.SessionImpl.postInsert(SessionImpl.java:2274)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2306)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2259)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2185)
at HibernateProcess.closeSession(HibernateProcess.java:50)
at HibernateProcess.processProcessingStopped(HibernateProcess.java:64)
at matcher.PerfectMatcherProcess.run(PerfectMatcherProcess.java:122)
at java.lang.Thread.run(Thread.java:536)

How can I handle this?

Thanks,

Thorsten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 2:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Call flush() between save() and evict(). Perhaps Hibernate is being a little bit too fussy by throwing an exception here, but I recall that there is another way that this can occur, which we are tryng to rule out.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 11:51 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I have the same problem as the one mentioned in the previous message. I cannot call flush between save and evict.

Is there any chance that hibernate do not throw this exception in future versions ?

Thanx

Seb


Top
 Profile  
 
 Post subject: that works!
PostPosted: Sun Nov 20, 2005 9:50 pm 
Newbie

Joined: Sun Nov 20, 2005 9:49 pm
Posts: 3
Location: Sydney, Australia
gavin thanks heaps - that soled the problem for something I'm working on.

_________________
~gautam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 7:00 am 
Beginner
Beginner

Joined: Wed Nov 29, 2006 10:32 am
Posts: 34
It seems to be a design decision that evict() does not work on new objects - i.e. objects that have been moved to the state "persistent" using save().

This contradicts the state diagrams shown e.g. in "Java Persistence with Hibernate" or "Hibernate in Action", but it seems to be accepted. In Frameworks which separate the creation of objects, including doing a save (e.g. when a factory decides whether to load the object from the DB; or create a new one - afterwards, we want the postcondition "object is in state persistent" to hold) from actions which might do an evict (because later the object might be shipped somewhere else) and which for some reason do not want to use the "workaround" to call flush(), this is quite a PITA ... but so it goes. However, I confess I have only looked into NHibernate 1.0.x and 1.2 and Hibernate 2.x - for newer versions, the software might actually follow the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 3:51 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
gavin wrote:
Call flush() between save() and evict(). Perhaps Hibernate is being a little bit too fussy by throwing an exception here, but I recall that there is another way that this can occur, which we are tryng to rule out.


I just bumped into this when I changed my id generators from native to increment. I removed the evict() calls and it works, so I just call session.clear() periodically.

Any idea why this happens?


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