a different object with the same identifier value was already associated with the session

当出现a different object with the same identifier value was already associated with the session时,一般是因为在hibernate中同一个session里面有了两个相同标识但是是不同实体。

我直接将接受需要比较的id的list<ab>换成了list<object[]>,再直接将值遍历拿出

就解决这个问题了

List<Object[]> objects=xxService.getObjList("select id from xx where abname=? and isd=0", ab.getabname()); 

Integer ins=(Integer)(Object)objects.get(0);

if( ab.getId() .equals(ins)){
 try {
  xxService.update(ab); 
 } catch (Exception e) {
  e.printStackTrace();
 }
}

posted @ 2015-03-30 14:12  gain  阅读(154)  评论(0编辑  收藏  举报