title: Saving/updating object with hibernate
body: <p>My class Foo has method:</p>
  
  <pre><code> protected void saveMany(Collection&lt;T&gt; many) {  
      for(Object one : many) {
              one = session.merge(one); // also tried this commented out
              session.saveOrUpdate(one); // session.merge(one);   
          }
  </code></pre>
  
  <p>Tried to use saveOrUpdate and also merge, but both gave me this exception:</p>
  
  <pre><code>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]
  </code></pre>
  
  <p><strong>How to fix this?</strong></p>
  
  <p>Side note:</p>
  
  <p><strong>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</strong></p>