打电话是个好习惯吗org.hibernate.Session.flush()
分别地?
正如中所述org.hibernate.Session
docs,
必须在工作单元结束时、提交事务并关闭会话之前调用(根据刷新模式,Transaction.commit() 调用此方法)。
你能解释一下打电话的目的吗flush()
明确地如果org.hibernate.Transaction.commit()
已经会这么做了吗?
在 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, same as the JDBC batch size
// flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
如果不调用flush方法,你的一级缓存将抛出OutOfMemoryException
另外你可以看看这篇关于冲水的帖子
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)