-->
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.  [ 5 posts ] 
Author Message
 Post subject: evict problem (or feature)?
PostPosted: Tue Jun 29, 2004 12:50 pm 
Beginner
Beginner

Joined: Tue Jun 29, 2004 12:35 pm
Posts: 21
Greets,

using hibernate 2.1.4

Is this normal or abnormal behavior of evict? (we are using hibernate's cache as peristable object cache in unit_of_work)

{
session.save(someObject); //cache object

(do some stuff w/someObject...and then decide to remove it)

session.evict(someObject); //remove ghost from cache

session.flush();

(commit transaction etc..)
}

previous example throws:
net.sf.hibernate.AssertionFailure: possible nonthreadsafe access to session

as flush still seems to try save evicted object into db.

Problem is, that Im flushing at the very end of transaction flow, (adding flush() between save and evict removes exception, but I do not want to save data before end).

Any workaround available or so?

Thanks,


Top
 Profile  
 
 Post subject: same problem here
PostPosted: Thu Feb 08, 2007 6:38 am 
Newbie

Joined: Mon Aug 23, 2004 7:54 am
Posts: 15
Hibernate 3.0

I have exactly the same problem:

Code:
Session hSes = sf.openSession();
Transaction tx = hSes.beginTransaction();
// prepare entity, set properties etc.
hSes.save(entity);
hSes.evict(entity);
t.commt(); // <- org.hibernate.AssertionFailure: possible nonthreadsafe access to session


What am I doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 6:53 am 
Newbie

Joined: Mon Aug 23, 2004 7:54 am
Posts: 15
I guess it was a stupid question... if I've evicted the entity from cache the commit() will not find it there! The error message confused me a little.

I've tried to use StatelessSession but I was hoping to take advantage of transactional write behind. My error


Top
 Profile  
 
 Post subject: Re: same problem here
PostPosted: Fri Oct 05, 2007 12:33 am 
Newbie

Joined: Mon Sep 17, 2007 11:42 pm
Posts: 16
Location: Auckland, New Zealand
bbb321 wrote:
Hibernate 3.0

I have exactly the same problem:

Code:
Session hSes = sf.openSession();
Transaction tx = hSes.beginTransaction();
// prepare entity, set properties etc.
hSes.save(entity);
hSes.evict(entity);
t.commt(); // <- org.hibernate.AssertionFailure: possible nonthreadsafe access to session


What am I doing wrong?


Try using flush() between save and evict. Hibernate is trying to protect you from evicting something that isn't in persistent state.


Top
 Profile  
 
 Post subject: Re: evict problem (or feature)?
PostPosted: Tue Feb 09, 2010 4:54 pm 
Newbie

Joined: Tue Feb 09, 2010 4:46 pm
Posts: 1
I experienced the same problem. The question is, if the session is must be flushed before I evict something and Hibernate is "protecting me", then why doesn't Hibernate just flush it for me? Especially, since I have flushmode set to AUTO!

It's pretty confusing getting a "nonthreadsafe" assertion when using known "Thread-safe" wrapper like HibernateTemplate for all of your operations just because you evicted something you previously saved (but before flush). It was especially odd getting it in a single transaction inside a single method of a single unit test. Umm... I only HAVE one thread!


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