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

這個問題是在一個事物中,先查出對象,在更新對象會報錯,由於更新的時候這個對象在session出現了主鍵重複,解決辦法:java

1.若是事物立刻要結束,能夠用sessionFactory.getCurrentSession().clear();session

2.若是後面還有其餘的操做,能夠在update以前在查詢一次,好比要保存People對象,code

peo=peopleService.findById(peo.getId());
peopleService.update(peo);
相關文章
相關標籤/搜索