2

尝试使用休眠删除记录时出现此异常。

org.hibernate.jdbc.BatchedTooManyRowsAffectedException:批量更新从更新[0]返回了意外的行数;实际行数:9;预期:1

我正在使用一个更新另一个表中的记录的实体(我有一个一对多的关系 - 一个“主”对象和一个单独表中的“辅助”对象列表)。我的设置正在尝试更新另一个表。这在创建和更新方法上工作得很好,但是当我尝试删除一个对象时,我得到了 BatchedTooManyRowsAffectedException 异常。

知道为什么会这样吗?

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)

我正在使用 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>

班级代码:

 ReportStock reportStock= this.getReportStock(reportId);
 session.get().delete(reportStock);
 session.get().flush();
4

0 回答 0