jQuery in Action, 2nd edition*
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

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2353)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:806)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:804)

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: 17258

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 - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
It is sorta covered in the JavaRanch Style Guide.
subject: StaleStateException