hibernate 中批量数据操作
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();