0

I want to perform CRUD operation using Spring MVC based Hibernate project, so far I have successfully performed add, delete operation. But while updating the data I am getting error show below. I tried adding my primary key to the session and retrieving it along the data to be updated from jsp page. But I am getting error exactly in the line hibernatetemplate.update(emp) line. Where emp is the object to be updated with same primary key as in database. I am using ECLIPSE IDE with Tomcat v9 server.

Servlet.service() for servlet [dispatcher] in context with path [/Demo] threw exception [Request processing failed; nested exception is org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [com.wipro.bean.Employee#254]; nested exception is org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.wipro.bean.Employee#254]] with root cause
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.wipro.bean.Employee#254]
  • see this https://stackoverflow.com/questions/1074081/hibernate-error-org-hibernate-nonuniqueobjectexception-a-different-object-with – Ganesh Giri Sep 29 '20 at 06:32

1 Answers1

0

I don't know the logic behind the solution but I used method hibernatetemplate.merge(emp) and it worked.