-->
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: How to recover from StaleObjectStateException?
PostPosted: Mon Aug 22, 2005 5:50 pm 
Newbie

Joined: Mon Aug 22, 2005 4:39 pm
Posts: 1
Location: Raleigh, NC, USA
Hibernate version:
2.1.7

Hi!

In our company we use Hibernate2 as a persistency framework for our rich-client application. Hibernate is deployed on the client side and that means that several instances of Hibernate access a database at the same time (so it is not a web application).
We use versioning (optimistic locking) to distinguish, if a row in a database was modified by another instance of Hibernate. Our session is “long”, actually it is very long, because it is opened when the application starts and it is closed when the application closes.
I’m trying to solve a problem, how to reload an object from the database if it was already loaded and modified by another instance of Hibernate (overriding any changes = first wins). My question is:

Is it possible to recover from StaleObjectStateException without closing the session? If yes, what is a common “pattern” how to do it?

I’ve tried to detach (evict(Object)) and reload (load(Object, Serializable)) the modified object, but I’m still getting the StaleObjectStateException during the subsequent flush() calls.

To close and reopen session seems to help, but then I have to deal with many other problems (like LazyInitializationExceptions) – just the application assumes that the objects are always attached.

Any help or idea would be highly appreciated. Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 7:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I am not a fan of very long session management. Having said that what you need to do is the clear the session cache then try the operation.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.