我的班级 Foo 有方法:
protected void saveMany(Collection<T> many) {
for(Object one : many) {
one = session.merge(one); // also tried this commented out
session.saveOrUpdate(one); // session.merge(one);
}
尝试使用 saveOrUpdate 并合并,但都给了我这个异常:
Error: Invocation of method 'saveMany' in class Foo threw exception class org.hibernate.HibernateException : org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [Bar#581301]
如何解决这个问题?
边注:
当我截断我的表时,保存部分可以工作,但是当我填充了表并再次运行此方法时,因此更新了表,它失败了,但有这个例外