File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes StaleStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "StaleStateException" Watch "StaleStateException" New topic


ayan sevi

Joined: Sep 21, 2006
Posts: 21
Hi ranchers,

Just want to know that in Hibernate when is this error happens?

Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(
at org.hibernate.persister.entity.AbstractEntityPersister.update(
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(
at org.hibernate.persister.entity.AbstractEntityPersister.update(
at org.hibernate.action.EntityUpdateAction.execute(
at org.hibernate.engine.ActionQueue.execute(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(
at org.hibernate.impl.SessionImpl.flush(
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(
at org.springframework.orm.hibernate3.HibernateTemplate.execute(
at org.springframework.orm.hibernate3.HibernateTemplate.flush(

Tried to look at the API, and it says

* Thrown when a version number or timestamp check failed, indicating that the
* <tt>Session</tt> contained stale data (when using long transactions
* with versioning). Also occurs if we try delete or update a row that does
* not exist.<br>
* <br>
* Note that this exception often indicates that the user failed to specify the
* correct <tt>unsaved-value</tt> strategy for a class!

Did I miss something here? I was just trying to remove a persistent object and then add a new persistent object, wherein, both objects have the same superclass (@MappedSuperClass), there, I have the version field contain in the superclass. Is there anything wrong here?

Any help is appreciated. Thanks.
ayan sevi

Joined: Sep 21, 2006
Posts: 21
Problem solved.

I should not have called the session.clear() executed by flush() from my source. Session clear, cancels all your pending transactions. Thus, reference to previous object after clear() is already stale.

Cheers, bryan
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I am a little confused. Your name shows as ayan, but you ended you post with "Cheer bryan", not that there is much difference, "a" versus "br" before the "yan" acually the difference between the two are two different html tags.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: StaleStateException
It's not a secret anymore!