Two Laptop Bag*
The moose likes Object Relational Mapping and the fly likes How to knock out StaleStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to knock out StaleStateException" Watch "How to knock out StaleStateException" New topic
Author

How to knock out StaleStateException

Renjith Mohan
Ranch Hand

Joined: Nov 28, 2008
Posts: 65

I am doing a small database application using j2se and hibernate. For the same, I have two databases - one primary and the other secondary. So I opened two sessions - each connecting to primary and secondary databases respectively.
Here is code:




When I run the code, I am getting exception as below:
SEVERE: Exception executing batch:
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.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2354)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2307)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2607)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
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.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.databaseclient.core.ApplicationTrigger.main(ApplicationTrigger.java:202)
Feb 6, 2009 11:03:52 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session

What is the approach for using two sessions in hibernate?
Anticipating early replies

Thank You
Javid Jamae
Author
Ranch Hand

Joined: May 14, 2008
Posts: 198
I'm not quite so sure it has to do with using two sessions. Are you using mapping files or annoations? What Java type are you using for your identifier? Are you using a primitive type? Are you setting the unsaved-value attribute?

Can you show us your domain object?


Author: JBoss in Action, javidjamae.com, @javidjamae on Twitter
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to knock out StaleStateException