我正在尝试从数据库中删除一条记录,但在删除它之前,我将它的一个子项复制到另一条记录中,这会遇到以下错误。
SEVERE: org.hibernate.StaleStateException: Batch update returned unexpected row count
from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:81)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:59)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3224)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3126)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3456)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:140)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:364)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:356)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:278)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
.....
1)在第一个函数中(从记录 18 中获取列表并添加到新记录)
....
User user = (User) session.get(User.class, 18L);
tx.commit();
User client = new User();
client.getmyList().setItems(user.getmyList().getItems());
return client;
2)在第二个功能(删除记录18)
User user = (User) session.get(User.class, 18L);
session.delete(user);
3)在第三个功能(保存新记录)
session.save(client);
用户类
@Entity
@DynamicUpdate
public class User{
.....
@OneToOne(cascade = CascadeType.ALL)
public UnitWatchList getmyList() {
return myList;
}
...
}