【问题标题】:Error in using HibernateTemplate update method使用 HibernateTemplate 更新方法时出错
【发布时间】:2020-09-29 22:51:47
【问题描述】:

我想使用基于 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]

【问题讨论】:

标签: spring hibernate session orm


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-30
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多