I'm facing the same problem like yours, I think what hibernate is trying to tell us is the Session can't sync with the state in database.
[What I did to duplicate this problem]
- it all works fine until I manually delete some records from back-end database while the program still running,
then it throws following exception ...
Code:
[java] org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
[java] at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
[java] at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
[java] at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
[java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
[java] at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:56)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2431)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
[java] at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
[java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
[java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
[java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
[java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
Can this consider a hibernate standard bug?
This issue is frustrating, been working on this stupid problem for 2 days, continuous testing and fixing and retesting ... (it goes on and on)
Is there any best practice to do couple of insert/update (which utilized few shared tables, erm ... assuming it's sequence of update is logical) in the same function?
[Additional Information]
Code:
=== HOST INFORMATION ===
Name: localhost
Host: localhost:3306
Server: MySQL
Version: 5.1.49-1ubuntu8.1
User: root
=== HIBERNATE VERSION ===
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: steve
Build-Jdk: 1.5.0_15
Specification-Title: Hibernate Core
Specification-Version: 3.3.0.SP1
Specification-Vendor: Hibernate.org
Implementation-Title: Hibernate Core
Implementation-Version: 3.3.0.SP1
Implementation-Vendor-Id: org.hibernate
Implementation-Vendor: Hibernate.org
Implementation-URL: http://hibernate.org/hibernate-core
Regards,
Avatar Ng