私のクラス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]
これを修正する方法は?
サイドノート:
テーブルを切り捨てると、保存部分は機能しますが、テーブルにデータを入力してこのメソッドを再度実行すると、テーブルが更新され、この例外が発生して失敗します