问题描述
两种方法都是得到同样的结果,求高手帮忙publicvoidupdate2(){Sessionsession=HibernateTools.currentSession();Transactiontx=session.beginTransaction();Stringhqlupdate="updateUsersetname=:newName";intupdateEntities=session.createQuery(hqlupdate).setString("newName","我不是一个人").executeUpdate();tx.commit();HibernateTools.closeSession();System.out.println("更新成功!");}publicvoidupdate1(){Sessionsession=HibernateTools.currentSession();Transactiontx=session.beginTransaction();ScrollableResultsusers=session.createQuery("fromUser").setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);intcount=0;while(users.next()){Useruser=(User)users.get(0);user.setName("我de"+count);if(++count%20==0){session.flush();session.clear();}}<?xmlversion="1.0"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mappingpackage="alex.com"><classname="User"><idname="id"column="userid"><generatorclass="identity"></generator></id><propertyname="name"/><propertyname="age"/><propertyname="nationality"/></class></hibernate-mapping>