2

Getting this exception while trying to delete record using hibernate.

org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 9; expected: 1

I am using an entity which updates records in another table (I have a one to many relation - one "primary" object with a list of "secondary" objects from a separate table). The settings I have in place are trying to update the other table. This worked fine on create and update methods, but when I attempted to delete an object, I got the BatchedTooManyRowsAffectedException exception.

any idea why is it happening?

org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:95)
org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:47)
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2691)
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2895)
org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
$Proxy679.flush(Unknown Source)

I am using SqlServer 2008.

     <hibernate-mapping>
<class name="com.send.ReportStock" table="COM_REPORT_STOCK">


    <id name="reportID" type="long">
        <column name="ReportID" />
        <generator class="assigned" />
    </id>

    <property name="Stock" type="java.math.BigDecimal">
        <column name="Stock" scale="9" not-null="true" />
    </property>
    <property name="Live" type="java.math.BigDecimal">
        <column name="Live" scale="9" not-null="true" />
    </property>


    <property generated="never" lazy="false" name="NotLiveStatic"
        type="java.lang.String">
        <column name="NotLiveStatic" />
    </property>


</class>
  </hibernate-mapping>

Class code:

 ReportStock reportStock= this.getReportStock(reportId);
 session.get().delete(reportStock);
 session.get().flush();
3
  • Can you add the class code and mappings?
    – Mr Mush
    Apr 21, 2013 at 13:15
  • @MrMush mapping added Apr 22, 2013 at 4:31
  • Where is the relation to the second table in your mapping? Also, could you post ReportStock class code?
    – Mr Mush
    Apr 23, 2013 at 7:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.