0
當我試圖更新數據庫的關鍵字段時,這個問題也來自session.flush()和session.clear()方法。org.hibernate.StaleStateException:批量更新從update [0]返回意外的行數;實際行數:0;預期:1
Bean.java
SessionFactory sf = HibernateUtil.getSessionFactory();
Session s = sf.openSession();
Criteria crit3=s.createCriteria(RoleTable.class);
roledata=crit3.list();
for(RoleTable rt:roledata){
Transaction tx = s.beginTransaction();
RoleTable rot=new RoleTable();
rot.setSno(1);
rot.setObtype(rt.getObtype());
rot.setObid(rt.getObid());
rot.setText(rt.getText());
rot.setSdat(rt.getSdat());
rot.setEdat(rt.getEdat());
rot.setUpdate(rt.isUpdate());
rot.setCreate(rt.isCreate());
rot.setDelete(rt.isDelete());
rot.setRead(rt.isRead());
s.update(rot);
s.flush();
s.clear();
tx.commit();
}
s.close();
sf.close();
}