我提到了很多文章,但仍然不清楚session.clear
在hibernate中的表現。session.clear()如何在Hibernate中工作
據我隔着那麼遠就是來了, 當我們使用批量保存/更新,如下圖所示:
Session session = SessionFactory.openSession();
Transaction tx = session.beginTransaction();
for (int i=0; i<100000; i++) {
Employee employee = new Employee(.....);
session.save(employee);
if(i % 50 == 0) { // Same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
sesion.flush();
法拉盛會話的力量是用來休眠到內存中狀態同步與數據庫的會話。
問題
沖洗會議結束後,爲什麼有必要做session.clear()
?它真的需要嗎?
2.請問session.clear()
執行提交操作?
3.如果session.clear()
驅逐所有加載的對象,執行提交和回滾操作時內部發生了什麼?