20:41:15
今天做一个saveorupdate操作报错:
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [com.xshcar.carcloud.entity.UboxTbl#1291]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.xshcar.carcloud.entity.UboxTbl#1291]
一个经典的hibernate错误:a different object with the same identifier value was already associated with the session xxxx
hibernate3.0以上使用merge()来合并两个session中的同一对象
解决:
在daoimpl层调用hibernate的getHibernateTemplate().merge(对象)方法;
public boolean executeUpdate(T t) { boolean b=true; try { t=(T)this.getHibernateTemplate().getSessionFactory().getCurrentSession().merge(t); getHibernateTemplate().update(t); } catch (DataAccessException e) { e.printStackTrace(); b=false; } return b; }
时间: 2024-10-31 13:27:46