-->
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: updating row multiple times in a single transaction
PostPosted: Fri Feb 25, 2005 6:15 am 
Newbie

Joined: Sun Dec 26, 2004 4:44 pm
Posts: 7
Location: Estonia
Hello,

I need to update a row several times during one transaction. For concurrency control I use versioning. The problem is that when I call save method on the second update I get StaleObjectStateException.

As far as I see, the problem is in incremented version number that Hibernate doesn't like, so it thinks that the object is stale. Is there some general pattern that we could employ to solve this issue?

wbr,
Vladimir

_________________
--------------------
wbr,
Vladimir


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 8:27 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Without your code (the red box!) I can just guess, that you're trying to save the same instance twice.

HTH
Ernst


Top
 Profile  
 
 Post subject: Re: updating row multiple times in a single transaction
PostPosted: Fri Feb 25, 2005 11:00 am 
Newbie

Joined: Fri Apr 16, 2004 9:27 am
Posts: 18
Location: Russia, Spb
t990922 wrote:
Hello,

I need to update a row several times during one transaction. For concurrency control I use versioning. The problem is that when I call save method on the second update I get StaleObjectStateException.

As far as I see, the problem is in incremented version number that Hibernate doesn't like, so it thinks that the object is stale. Is there some general pattern that we could employ to solve this issue?

wbr,
Vladimir


Try saveOrUpdate() method instead of save().


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, don't call save() or update() at all as long as you are within Session scope and not reattatching a detatched object. Automatic dirty checking is there for this.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 5:13 am 
Newbie

Joined: Sun Dec 26, 2004 4:44 pm
Posts: 7
Location: Estonia
I'm using this object in different sessions, at least I hope so, couse I get these sessions from SessionFactory.
And I'm actually using saveOrUpdate method, not save.
Any more ideas?

_________________
--------------------
wbr,
Vladimir


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.