-->
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: Batch update returned unexpected row count from update [0];
PostPosted: Thu Jun 12, 2008 3:17 pm 
Newbie

Joined: Sat Dec 02, 2006 1:09 am
Posts: 12
I am getting the following error:

.....Message_Error : 'com.x.exceptions.PtRuntimeException: CallResult: addException():org.springframew
ork.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0
]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpe
cted row count from update [0]; actual row count: 0; expected: 1

---
This is what I am trying to do:

Every now and then I issue a delete statement. I do not know if there are any rows in the database that will actually be deleted or not. There may be a row deleted, there may be 0 rows deleted.

If there are actually 0 rows to be deleted, I see the error above. Hibernate assumes that this is an error. Is there a way to tell hibernate to not assume that it is an error and keep going if it deleted 0 rows?

thanks

JavaTek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 9:15 am 
Newbie

Joined: Wed Jul 23, 2008 6:19 am
Posts: 4
I believe you get this error when the objects in the Hibernate Session don't match the database.

This can happen due to multiple threads accessing the same objects, database rollbacks etc.

For example, I can cause this error as follows:
1) Let Hibernate transaction time out after 'saving' objects. This causes an exception. Database is rolled back but session still thinks the object has been updated.
2) Do an update on the same objects. Hibernate assumes that the object is in the database and throws the error when it doesn't find it.

To solve the problem, I changed to use merge instead of update. This commits your changes without assuming that the database and session are in line. Alternatively, you could try catching the exception, closing and clearing the session and retrying the transaction.


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.