-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Batch update returned unexpected row count with BLOB propert
PostPosted: Wed Feb 23, 2005 6:30 pm 
Newbie

Joined: Thu Jan 27, 2005 7:55 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: Batch update returned unexpected row count with BLOB propert
PostPosted: Fri Sep 11, 2009 7:23 am 
Newbie

Joined: Fri Sep 11, 2009 7:11 am
Posts: 2
When do you see this kind of error in Hibernate? When your code is trying to update objects and some of them getting changed at the same time in different transaction. When executing update Hibernate keep track of number of rows affected in database by DML operation and throw StaleStateException if number of updated rows are less than expected (some records which your original query returned cannot be found with this criteria anymore) or just generic HibernateException in opposite case


Thanks
Ravi
macha_ravir@yahoo.co.in


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.