首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate批量安插的方法

2012-11-10 
Hibernate批量插入的方法Session session sessionFactory.openSession()Transaction tx session.begi

Hibernate批量插入的方法

  Session session = sessionFactory.openSession();    Transaction tx = session.beginTransaction();      for ( int i=0; i<100000; i++ ) {     Customer customer = new Customer(.....);     session.save(customer);     if ( i % 20 == 0 ) {       //20,与JDBC批量设置相同        //将本批插入的对象立即写入数据库并释放内存         session.flush();        session.clear();     }   }      tx.commit();   session.close(); 

?

热点排行