0
我目前在使用Hibernate作爲持久性管理器和JPA作爲持久性管理休眠的抽象的java中開發應用程序。從數據庫中獲取對象時,JPA(Hibernate)如何處理事務
我想知道圍繞事務打包結果查詢的影響。我知道實體經理必須保持開放,懶惰地提取字段錯誤所有這些交易是什麼?
這裏是一個事務激活/去激活能力的代碼示例。
public List<Exportdata> get(Integer max, EntityManager em, Boolean withTransaction) {
EntityTransaction tx = null;
try {
if (withTransaction) {
tx = em.getTransaction();
tx.begin();
}
Query query = em.createQuery("from Exportdata");
query.setMaxResults(10);
List<Exportdata> list = query.getResultList();
if (withTransaction)
tx.commit();
return list;
} catch (RuntimeException re) {
if (withTransaction)
if (tx != null && tx.isActive())
tx.rollback();
throw re;
}
}
當調用此函數時啓用或禁用withTransaction與區別?
感謝所有, 弗雷德
「如果您開始操作從此方法返回的列表中的對象,那麼這些更改將傳播回數據庫 - 特別是基於事務的事務。」這是否適用於關閉或兩種情況? – 2008-10-29 23:46:32