使用HibernateTemplate更新方法出错

Error in using HibernateTemplate update method

我想使用Spring基于MVC的Hibernate项目进行CRUD操作,目前已经成功进行了增删改查。但是在更新数据时,我收到如下错误信息。我尝试将我的主键添加到会话中,并沿着要从 jsp 页面更新的数据检索它。但是我在 hibernatetemplate.update(emp) 行中收到错误。其中 emp 是要使用与数据库中相同的主键更新的对象。我正在使用 ECLIPSE IDE 和 Tomcat v9 服务器。

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]

我不知道解决方案背后的逻辑,但我使用了方法 hibernatetemplate.merge(emp) 并且有效.