【发布时间】:2012-11-12 09:59:54
【问题描述】:
为什么我需要在 Hibernate 中进行 Transaction 才能进行只读操作?
以下事务是否在数据库中加了锁?
从数据库中获取的示例代码:
Transaction tx = HibernateUtil.getCurrentSession().beginTransaction(); // why begin transaction?
//readonly operation here
tx.commit() // why tx.commit? I don't want to write anything
我可以使用session.close() 代替tx.commit() 吗?
【问题讨论】:
-
事务是数据库本身需要的。您可以在此处阅读有关自动提交模式的信息:community.jboss.org/wiki/…
-
@BheshGurung 我想我们只需要为写操作进行事务处理
-
您是否阅读了链接中的“揭穿自动提交神话”部分?
标签: java database hibernate transactions database-connection