-->
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: StaleObjectStateException
PostPosted: Tue Dec 14, 2004 10:09 am 
Newbie

Joined: Tue Dec 07, 2004 7:51 am
Posts: 7
While modifying a record in the database through hibernate API update function, I get "StaleObjectStateException" error sometimes.

The full error message is:

WARNING: An operation failed due to stale data
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)



I am doing optimistic concurreny check for this table through one timestamp field in the table. And this timestamp value, I am not changing while each updation of the record. I am keeping it same. Can that be causing this issue ? I mean if I make this timestamp field to be automatically generated at DB side while any modification, it might work out.

Please provide me any pointers to resolve the issue.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 3:09 pm 
Newbie

Joined: Sat Jul 17, 2004 5:13 pm
Posts: 8
Location: Edegem, Belgium
Quote:
I am doing optimistic concurreny check for this table through one timestamp field in the table. And this timestamp value, I am not changing while each updation of the record. I am keeping it same. Can that be causing this issue ? I mean if I make this timestamp field to be automatically generated at DB side while any modification, it might work out.


Mostly I don't use timestamps, but the specific <version> tag. Something along the lines of:

Code:
<class name="Category" table="CATEGORY" lazy="true">
  <id name="id" column="CATEGORY_ID">
    <generator class="native"/>
  </id>

  <!-- Versioned entity. -->
  <version name="version" column="VERSION"/>

[rest of mapping]


And in the java code something like:

Code:
public class Category {
  private Long id;
  private int version;


The version is automatically updated by Hibernate. You don't have to touch it yourself. Everytime your object is saved, you should see in the database a version update.

If Hibernate finds a mismatch (because somebody else updated the row), Hibernate will throw the "StaleObjectStateException".

Regards,

Jos


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.