![](/img/trans.png)
[英]org.hibernate.PersistentObjectException: detached entity passed to persist MERGE
[英]Hibernate cannot merge and persist two instances of entity class
當我嘗試更新Team
Hibernate時引發異常:
Multiple representations of the same entity [Team#1] are being merged.
Detached: [Team@49a0aef3]; Managed: [Team@bf505c]
TeamDAOImpl
public void updateTeam(Team team) {
Team teamToUpdate = getTeam(team.getId());
teamToUpdate.setName(team.getName());
team = null; // doesn't help to avoid exception
getCurrentSession().merge(teamToUpdate);
}
public Team getTeam(int id) {
Team team = (Team) getCurrentSession().get(Team.class, id);
return team;
}
我已經看到了與此異常相關的大多數問題,但是還沒有找到有效的解決方案。 如何解決?
更新:
這似乎是Hibernate團隊必須修復的某種錯誤 。 就我而言,邏輯極其瑣碎,我不敢相信Hibernate無法更新當前實體。 必須有一種方法。
通過從源實體中刪除CascadeType來修復此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.