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

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,再查询.

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

报告相同问题?