尝试使用hibernate删除记录时获取此异常。
org.hibernate.jdbc.BatchedTooManyRowsAffectedException:批量更新从update [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();