Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

来源:互联网 发布:淘宝摄影市场 编辑:程序博客网 时间:2024/04/30 08:40
错误信息:
ERROR 06-28 14:14:04,289 (AbstractFlushingEventListener.java:324)org.hibernate.event.def.AbstractFlushingEventListener.performExecutions 
Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
诡异的是我的项目中报出此错的行是一个查询数据库的操作。报错的行是:translog = transLogDao.findUniqueBy(......这一行。
for (Pickdetail pd : listPickdetails) {
key = new StringBuffer();
//根据盒条码、出库单号查询交易记录
translog = transLogDao.findUniqueBy(new String[] {"barCode", "orderCode"}, new String[] {pd.getBarCode(), orders.getOrderCode()});
if (translog == null) continue;
key.append(translog.getCompcode()).append(",").append(translog.getSectionCode()).append(
",").append(translog.getLoc()).append(",").append(translog.getSkuCode());
if (mapStock.containsKey(key.toString())) {
temp = mapStock.get(key.toString());
mapStock.put(key.toString(), ++temp);
} else {
mapStock.put(key.toString(), 1);
}
stockBarCode = new StockBarCode();
//增加非生产库存条码 并生成交易记录
saveStockBarCode(stockBarCode, pd, orders);
//删掉此条拣货明细
pickdetailDao.remove(pickdetail);
success++;
}
我的项目产生此异常原因:pickdetailDao.remove(pickdetail);主要是这句话的问题。pickdetail变量是我在循环外定义得一个对象,该对象一直没有改变过。
而我这里本意是遍历listPickdetails集合,依次删除该集合中的每个pickdetail对象,所以应该是pickdetailDao.remove(pd);结果疏忽,整成了pickdetailDao.remove(pickdetail);
在循环中每一次删除的都是同一个pickdetail对象,所以报此错,只是报错的位置有点诡异。