public void updateSessionStatus() { Session sess = factory.openSession(); Transaction tx = null; try { tx = sess.beginTransaction(); Criteria crit = sess.createCriteria(CollegeStudentsMaster.class); crit.add(Restrictions.eqProperty("academicYear", "courseYears")); // Here is updated pre ScrollableResults items = crit.scroll(); int count=0; while ( items.next() ) { CollegeStudentsMaster e = (CollegeStudentsMaster)items.get(0); e.setSessionStatus("G"); sess.saveOrUpdate(e); if ( ++count % 100 == 0 ) { sess.flush(); sess.clear(); } } tx.commit(); } catch (HibernateException asd) { if (tx != null) { tx.rollback(); } log.debug(asd.getMessage()); } finally { sess.close(); } }始终建议执行批量操作非常接近数据库,除非需要,否则我们不需要在会话中保留更新的对象,因此,在执行批量操作时,请避免在会话中加载对象。



