title: How to solve org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
body: <p>I'm saving a <code>List</code> by using hibernate, but it throws the following exception: </p>
  
  <pre><code>org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
  </code></pre>
  
  <p>The code I'm using is below, but I don't know why it throws the exception:</p>
  
  <pre><code>public void save(List&lt;UserItem&gt; list)
  {
      //getHibernateTemplate().saveOrUpdateAll(list);
  
      //getHibernateTemplate().deleteAll(list);
      sessFactory = getHibernateTemplate().getSessionFactory();
      Session session = sessFactory.getCurrentSession();
      for (UserItem bean : list) {
          session.saveOrUpdate(bean);
      }
  }
  </code></pre>
  
  <p>What is the correct way to save the <code>List</code>?</p>