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 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to knock out StaleStateException" Watch "How to knock out StaleStateException" New topic

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(
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(
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.hibernate.impl.SessionImpl.managedFlush(
at org.hibernate.transaction.JDBCTransaction.commit(
at com.databaseclient.core.ApplicationTrigger.main(
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
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 on Twitter
I agree. Here's the link:
subject: How to knock out StaleStateException
Similar Threads
How to solve this exception? and what the mistake I have done in my code??
Exception while inserting a row using Hibernate
Problem with inserting new data into database using hibernate
Hibernate 3.0 : Where am I going wrong?