dream11867 2008-11-18 15:26
浏览 554
已采纳

different object with the same identifier value wa

INFO com.c35.paris.dao.impl.UserDAOImpl.modifyById(UserDAOImpl.java:114) - modifyById method is running!
ERROR com.c35.paris.dao.impl.UserDAOImpl.modifyById(UserDAOImpl.java:121) - org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.c35.paris.vo.User#8aa3b3671d8ebd4c011d8ec457980003]
org.hibernate.HibernateException: 修改数据出错!a different object with the same identifier value was already associated with the session: [com.c35.paris.vo.User#8aa3b3671d8ebd4c011d8ec457980003]
[b]问题补充:[/b]
INFO com.c35.paris.dao.impl.UserDAOImpl.modifyById(UserDAOImpl.java:114) - modifyById method is running!
ERROR com.c35.paris.dao.impl.UserDAOImpl.modifyById(UserDAOImpl.java:121) - org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.c35.paris.vo.User#8aa3b3671d8ebd4c011d8ec457980003]
org.hibernate.HibernateException: 修改数据出错!a different object with the same identifier value was already associated with the session: [com.c35.paris.vo.User#8aa3b3671d8ebd4c011d8ec457980003]

怎么修改,
是下面的方法错了么?
public boolean modifyById(String id, Object o)throws Exception {
boolean flag=false;
log.info("modifyById method is running!");
Transaction tran = null;
try {
tran = session.beginTransaction();
this.session.update(o);
flag=true;
} catch (HibernateException e) {
log.error(e.toString());

flag=false;
throw new HibernateException("修改数据出错!"+e.getMessage()) ;
}
return flag;

}

[b]问题补充:[/b]
INFO com.c35.paris.dao.impl.UserDAOImpl.modifyById(UserDAOImpl.java:114) - modifyById method is running!
ERROR com.c35.paris.dao.impl.UserDAOImpl.modifyById(UserDAOImpl.java:121) - org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.c35.paris.vo.User#8aa3b3671d8ebd4c011d8ec457980003]
org.hibernate.HibernateException: 修改数据出错!a different object with the same identifier value was already associated with the session: [com.c35.paris.vo.User#8aa3b3671d8ebd4c011d8ec457980003]
问题补充:

怎么修改,
是下面的方法错了么?
public boolean modifyById(String id, Object o)throws Exception {
boolean flag=false;
log.info("modifyById method is running!");
Transaction tran = null;
try {
tran = session.beginTransaction();
this.session.update(o);
flag=true;
} catch (HibernateException e) {
log.error(e.toString());

flag=false;
throw new HibernateException("修改数据出错!"+e.getMessage()) ;
}
return flag;

}
  • 写回答

1条回答 默认 最新

  • bohemia 2008-11-18 15:31
    关注

    [quote]a different object with the same identifier value was already associated with the session[/quote]
    提示很明显了.
    你的Session已经加载了一个相同ID的对象了. 直接UPdate,再查询.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?