org.hibernate.NonUniqueObjectException

今天用SSH框架写点东西就曝出这个错误

出现问题的代码块是这样的

/** 修改 */public String edit() throws Exception {// 从数据库中取出对象Forum forum = forumService.getById(model.getId());// 设置要修改的属性forum.setName(model.getName());forum.setDescription(model.getDescription());// 更新到数据库forumService.update(model);return "toList";}

就是说登录后在修改时session中存在两个标识相同的实体

把前面的代码注释掉

/** 修改 */public String edit() throws Exception {// 从数据库中取出对象//Forum forum = forumService.getById(model.getId());//// 设置要修改的属性//forum.setName(model.getName());//forum.setDescription(model.getDescription());// 更新到数据库forumService.update(model);return "toList";}可以了!

基本类中涉及到更新操作:

protected Session getSession() {return sessionFactory.getCurrentSession();}

public void update(T entity) {getSession().update(entity);}

这个应该是缓存的问题,会话没有及时更新

版权声明:本文为博主原创文章,未经博主允许不得转载。如需转载,请注明出处:

,鱼儿爱美,不仅需要鳞甲之美。还需要浮沉活泼之美。

org.hibernate.NonUniqueObjectException

相关文章:

你感兴趣的文章:

标签云: