Hibernate version:
Hibernate3 beta 4b
Mapping documents:
<class name="Dokument" table="dokument">
<id name="dokumentId" column="dokument_id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="name" column="name" type="java.lang.String" length="255"/>
<property name="contentType" column="mime_content_type" type="java.lang.String" length="255"/>
<property name="datum" column="datum" type="date" />
<property name="content" column="content" type="blob" />
<property name="notizen" column="notizen" type="java.lang.String" />
</class>
<class name="Partner" table="partner">
<meta attribute="implement-equals">true</meta>
<id name="partnerId" column="partner_id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="name" column="name" type="java.lang.String" length="50" not-null="true"/>
<set name="dokumente"
table="partner_dokument"
inverse="true"
lazy="true"
cascade="all-delete-orphan">
<key column="partner_id" />
<one-to-many class="Dokument"/>
</set>
</class>
Code between sessionFactory.openSession() and session.close():
// we have an Partner Object in o from another session
Partner o;
Session session=SimpleDbFactory.createSession();
Transaction t=session.beginTransaction();
try{
session.update(o);
// do some editing only on children of the 'dokumente' set like calling setNotizen("bla") on MORE THAN 1 of the children so a batch update will be triggered
if (res==null){
session.refresh(o);
t.rollback();
t=null;
}
else{
// session.flush();
t.commit();
t=null;
}
} finally {
if (t!=null){
t.rollback();
}
if (session!=null)
session.close();
}
Full stack trace of any exception that occurs:
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 1 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:89)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:75)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:155)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:271)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:24)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:719)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:84)
Name and version of the database you are using:
MySQL 4.1.9-nt
Debug level Hibernate log excerpt:
Quote:
BatchingBatcher.java:55 DEBUG : Executing batch size: 1
AbstractBatcher.java:267 DEBUG : about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
AbstractBatcher.java:368 DEBUG : closing statement
SessionImpl.java:162 DEBUG : running Session.finalize()
AbstractBatcher.java:259 DEBUG : about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
AbstractBatcher.java:297 DEBUG : update dokument set name=?, mime_content_type=?, datum=?, content=?, notizen=?, login_id=? where dokument_id=?
AbstractBatcher.java:348 DEBUG : preparing statement
BasicEntityPersister.java:1536 DEBUG : Dehydrating entity: [Dokument#2]
NullableType.java:56 DEBUG : binding '.cvsignore' to parameter: 1
NullableType.java:56 DEBUG : binding '' to parameter: 2
NullableType.java:56 DEBUG : binding '23 Februar 2005' to parameter: 3
NullableType.java:56 DEBUG : binding 'com.mysql.jdbc.Blob@e2892b' to parameter: 4
NullableType.java:56 DEBUG : binding 'test345345' to parameter: 5
NullableType.java:56 DEBUG : binding '1' to parameter: 6
Hibernate: update dokument set name=?, mime_content_type=?, datum=?, content=?, notizen=?, login_id=? where dokument_id=?
NullableType.java:56 DEBUG : binding '2' to parameter: 7
BatchingBatcher.java:28 DEBUG : Adding to batch
BasicEntityPersister.java:1859 DEBUG : Updating entity: [Dokument#4]
AbstractBatcher.java:135 DEBUG : reusing prepared statement
AbstractBatcher.java:297 DEBUG : update dokument set name=?, mime_content_type=?, datum=?, content=?, notizen=?, login_id=? where dokument_id=?
BasicEntityPersister.java:1536 DEBUG : Dehydrating entity: [Dokument#4]
NullableType.java:56 DEBUG : binding '.cvsignore' to parameter: 1
NullableType.java:56 DEBUG : binding '' to parameter: 2
NullableType.java:56 DEBUG : binding '23 Februar 2005' to parameter: 3
NullableType.java:56 DEBUG : binding 'com.mysql.jdbc.Blob@1dd9891' to parameter: 4
NullableType.java:56 DEBUG : binding 'test4' to parameter: 5
NullableType.java:56 DEBUG : binding '1' to parameter: 6
NullableType.java:56 DEBUG : binding '4' to parameter: 7
BatchingBatcher.java:28 DEBUG : Adding to batch
BatchingBatcher.java:55 DEBUG : Executing batch size: 2
BatchingBatcher.java:61 ERROR : Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 1 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:89)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:75)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:155)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:271)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:24)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:719)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:84)
Hibernate: update dokument set name=?, mime_content_type=?, datum=?, content=?, notizen=?, login_id=? where dokument_id=?
AbstractBatcher.java:267 DEBUG : about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
AbstractBatcher.java:368 DEBUG : closing statement
The error only occurs if there is a blob property in the updated object. The blob isn't changed in the example but an arbitrary other value.
It won't happen if there is no blob property or only one of the Dokument objects in the set is changed.