java - org.hibernate.StaleStateException:Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 -
when trying update key fields in database problem comes using session.flush() , session.clear() methods.
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(); }
it because commit transaction after flushing session, change sequence of below:
tx.commit(); s.flush(); s.clear();
Comments
Post a Comment