My class Foo has method:
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);
}
Tried to use saveOrUpdate and also merge, but both gave me this exception:
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]
How to fix this?
Side note:
When I truncate my table, the saving part works, but when I have the table populated, and run this method again, thus updating the table, it fails, with this exception