现在的位置: 首页 > 综合 > 正文

在使用hibernate项目中,持久化类的ID用Long与long有很大区别!!

2018年02月08日 ⁄ 综合 ⁄ 共 355字 ⁄ 字号 评论关闭

在使用hibernate项目中,持久化类的ID用Long与long有很大区别!!
用long 作为id,当一个新的临时类要持久化时会报一个这种错:
Exception executing batch
: org.hibernate.StaleStateException: Batch
update
returned
unexpected
row
count
from

update:
0
actual row
count
: 0
expected: 1
因为这个临时类,已经有一个id=0 (long的默认值);这时hibernate 为错认为这是一条持久化类,从而进行更新操作,故报错!!
这时把持久类的id 类型改成Long 就OK了,再create 时,临时类的id为null ,hibernate 才会正确的判断这是临时类而进行save操作!!

 

以此类推。。。。。

抱歉!评论已关闭.