早教吧作业答案频道 -->其他-->
Hibernateexception:adifferentobjectwiththesameidentifiervaluewasalreadyassociatedwithth当出现adifferentobjectwiththesameidentifiervaluewasalreadyassociatedwiththesession时,一般是因为在hibernate中同一个session
题目详情
Hibernate exception:a different object with the same identifier value was already associated with th当出现a different object with the same identifier value was already associated with the session时,一般是因为在hibernate中同一个session里面有了两个相同标识但是是不同实体。 我测试了网上所有的解决方案,包括: (1)使用session.clean(),如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。 (2)使用session.refresh(object),当object不是数据库中已有数据的对象的时候,不能使用 session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。 (3)session.merge(object),Hibernate里面自带的方法,推荐使用。 最后发现只有session.clear()可行,但是项目要求不能使用session.clear(),大家有什么好的想法能帮助下吗,谢谢
▼优质解答
答案和解析
你用查出来的最新的对象,向数据库里插入.虽然麻烦,但是可以奏效
看了Hibernateexcept...的网友还看了以下:
已知字母组合成英语单词1、e e t t i n h r 2、e e r a t w h 3、o 2020-05-14 …
英语高手傍忙拼几个单词!X,I,A,O,F,E,I,W,O,A,I,N,I打头的 2020-07-13 …
已知全集I=N,集合A={x|x=2n,n∈N},B={x|x=4n,n∈N},则()A.I=A∪ 2020-07-30 …
1.集合{z|z=i^n+i^(n-1,n属于z},用列举法表示该集合,这个集合是()A{0,2, 2020-08-01 …
数列极限lim{((1³+2³+...n³)/n³)-4/n},n趋于无穷的极限?(1³+2³+.. 2020-11-01 …
关于普通年金终值计算公式,始终搞不明白怎么来的书上是这样的:F=A(1+i)^0+A(1+i)^1+ 2020-11-01 …
下证明过程中蕴涵的数学思想是什么s=a+a(1+i)+a(1+i)(1+i)+...+a(1+i)的 2020-11-01 …
英语向高人求教!写几句话.每句开头的第一个字母分别是“L,i,U,F,E,i,F,E,i,w,o,a 2020-12-15 …
在资金时间价值计算时,i和n给定,下列等式中正确的有().A.(F/A,i,n)=[(P/F,i,n 2021-01-14 …
1、在资金时间价值计算时,i和n给定,下列等式中正确的有?为什么?1、A(F/A,i,n)=[(P/ 2021-01-14 …