在使用hibernate項目中,持久化類的ID用Long與long有很大區(qū)別!!
用long 作為id,當(dāng)一個新的臨時類要持久化時會報一個這種錯:
Exception executing
batch: org.hibernate.StaleStateException:
Batch update returned unexpected row count from update: 0 actual
row count:
0 expected: 1
因為這個臨時類,已經(jīng)有一個id=0 (long的默認(rèn)值);這時hibernate 為錯認(rèn)為這是一條持久化類,從而進(jìn)行更新操作,故報錯!!
這時把持久類的id 類型改成Long 就OK了,再create 時,臨時類的id為null ,hibernate 才會正確的判斷這是臨時類而進(jìn)行save操作!!
posted on 2007-09-28 11:42
摩西 閱讀(2444)
評論(1) 編輯 收藏 所屬分類:
work_2007