-->
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 get around a StaleStateException
PostPosted: Mon Jul 27, 2009 9:53 am 
Newbie

Joined: Fri Dec 12, 2008 8:07 am
Posts: 3
Hello all,

My app does the following:-

1. Starts a transaction
2. It needs to perform an operation until a positive result is obtained.
3. The operation goes like, retrieve data from the data, perform checks and delete some of the data
4. At the start of every iteration I go to the database to fetch data, and during one of those fetches I get a StaleStateException

Can anyone suggest a way forward please?

Cheers
Gokul


Top
 Profile  
 
 Post subject: Re: How to get around a StaleStateException
PostPosted: Tue Jul 28, 2009 10:43 am 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Hello Gokul,
Here are my thoughts:- you need to understand why you are getting the StaleObjectException in order to get around with it.
In my experience in our app here is one of the scenario where I have encountered the StaleObectException. I'm not sure but the guess is that you are having the same issue.
Parent Object having Set/List of children and making changes to the children automatically triggers to flag the Parent Object as "Dirty" and needs to be synced to the database. So saving the Parent and get the re-synced object of the Parent is important.
For example:- Instance Cat has Set of Kitten objects and making changes to the Kitten Objects makes the Version column(Version column or some flag in your app to store the state of the object by Hibernate) on the Cat to get bumped up.Saving the Cat is the right thing to do but you need to get the Cat instance again from the database.
Cat c .. Version 1
getKittens..
deleteKitten
updateKitten
Save Cat The state of the Kittens is updated and Cat gets the Version 2 in the database.
cat.getkittens -- Will cause Hibernate to throw StaleObjectException since Hibernate has an issue with the State of the cat. Get the instance of the Cat again from the database. Nothing has technically changed except for the State(or the Version column) on the object.
Get the Cat from db and then cat.getKittens to avoid the StaleObjectException.

Hope this helps,
Srilatha.


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.