[英]Hibernate Jpa batch insert not working
我正在使用hibernate jpa執行批處理更新。
它沒有給出任何錯誤或異常,但是事務在每次給出時都會回滾。
2015-04-21 16:30:33,548 ERROR [org.jboss.as.ejb3] (Thread-344 (HornetQ-client-global-threads-462057890)) javax.ejb.EJBTransactionRolledbackException: no transaction is in progress
這是我的批量更新代碼
getEm().getTransaction().begin();
System.out.println("transaction started--------------");
try{
for(Receipt ReceiptEntity : arrReceiptEntity){
getEm().persist(ReceiptEntity);
}
getEm().getTransaction().commit();
System.out.println("commited");
}catch(Exception exception){
System.out.println("error----------------------------------------------------------------------");
if(getEm().getTransaction().isActive())
getEm().getTransaction().rollback();
LOG.error(exception);
}finally
{
getEm().flush();
getEm().clear();
getEm().close();
}
我正在使用Postgres服務器9.4.1,請幫助我弄清楚我在做什么錯。 我檢查了其他類似的職位,但沒有任何幫助。
更新:我得到了解決方案:問題是我正在刷新已經刷新的事務,因此它沒有上面顯示的事務,也沒有出現正在進行的事務錯誤,所以我只是刪除了`getEm()。flush() ; 和getEm()。clear(); 從finally塊開始,它開始工作:)
我得到了解決方案:問題是我正在刷新已刷新的事務。因此,它沒有上面顯示的事務,因此沒有正在進行的事務錯誤。所以我只刪除了getEm().flush(); and getEm().clear();
getEm().flush(); and getEm().clear();
從finally塊開始,它開始工作:)
希望對別人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.