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