[問題] Hibernate executeUpdate的問題

作者: lueichun (no anonymous)   2020-07-23 16:15:17
※狀況概述:
以下的程式,執行第一次update時還可以跑到commit,但是在頁面上
仍然顯示修改前的結果。
但第二次執行update時,就卡住到不了commit。
※程式碼:
public void edit(Customer customer){
Transaction tx = getSession().beginTransaction();
try {
SQLQuery query = getSession().createSQLQuery("update CUSTOMER set
NAME='"+customer.getName()+"', ADDRESS='"+customer.getAddress()+"'"+
" where CUSTOMER_ID="+customer.getCustomerId()+"");
query.executeUpdate();
tx.commit();
}catch (Exception e) {
tx.rollback();
}
}
※錯誤訊息:
沒跳錯誤訊息,就是一直卡住不動。
※補充說明:
我把上面產生出來的SQL,貼到sqldeveloper上面去執行,是可以正常執行的。
為甚麼update後有執行commit,之後的update卻仍然卡住,請問卡住不動的原因是什麼呢?
另外我將以上的寫法改成:
getHibernateTemplate().update(customer);
結果也是一樣。
作者: swallowcc (guest)   2020-07-23 17:05:00
e.printstacktrace() 貼上去看一下錯誤...
作者: tw11509 (John-117)   2020-07-23 23:53:00
真的想追原因的話,試著用debugger吧
作者: achaos (熱~~~~)   2020-07-24 22:07:00
我猜少了session.close
作者: rexking1022   2020-07-26 14:55:00
同上,commit後,連線沒關,可以試試看程式跑完後到DB執行for update,如果lock就是沒關連線
作者: fgh81113 (阿景)   2020-07-26 22:25:00
是不是第一個的getSession()用static放session

Links booklink

Contact Us: admin [ a t ] ucptt.com