Hibernate批量处理数据.docxVIP

  • 2
  • 0
  • 约8.36千字
  • 约 8页
  • 2016-08-26 发布于河南
  • 举报
Hibernate批量处理数据

通常,在一个Session对象的缓存中只存放数量有限的持久化对象,等到Session对象处理事务完毕,还要关闭Session对象,从而及时释放Session的缓存占用的内存。批量处理数据是指在一个事务中处理大量数据。以下程序在一个事务中批量更新CUSTOMERS表中年龄大于零的所有记录的AGE字段:Transaction tx = session.beginTransaction();Iterator customers=session.createQuery(from Customer c where c.age0).list().iterator();while(customers.hasNext()){Customer customer=(Customer)customers.next();customer.setAge(customer.getAge()+1);}mit();session.close();如果CUSTOMERS表中有1万条年龄大于零的记录,那么Hibernate会一下子加载1万个Customer对象到内存。当执行mit()方法时,会清理缓存,Hibernate执行1万条更新CUSTOMERS表的update语句:update CUSTOMERS set AGE=? …. where ID=i;update CUSTOMERS set AGE=? …. wh

文档评论(0)

1亿VIP精品文档

相关文档