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 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口