ITeye博客

hibernate 中批量数据操作

mjbb · 2010-03-07 21:09 · Java小技巧 · 企业架构 · Markdown

s = sf.openSession(); //s.setFlushMode(FlushMode.NEVER); 只有在flush的时候才提交数据 flush 默认情况是在commit()时候才执行的 tx = s.beginTx(); Customer c = null; for(int i = 0 ; i < 100000 ; i++){ c = new Customer(); c.setXXX(...); //... s.save(c); if((i % 2000) == 0){ s.flush(); s.clear(); } } s.flush();//************ 不加该方法会丢失数据. tx.commit(); s.close();

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。