2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Hibernate Error: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

I have two Customer Objects and which iam trying to save like this :


BaseHibernateDAO dao = new BaseHibernateDAO();          

session = dao.getSession(customerDetails.getRegion(),

                           BaseHibernateDAO.RTREQUESTS_DATABASE_NAME);

trans = session.beginTransaction();

trans.begin();

session.save(customerOne);

session.save(customerTwo);

session.flush();

trans.commit();

session.close(); // in finally block


I am getting the following error:

Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

[com.pojo.rtrequests.Customer#com.pojo.rtrequests.Customer@d097c00b]

Answer is