When I try to update Team
Hibernate throws exception:
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;
}
I have seen most issues related to this exception but haven't found solution that works. How to fix it?
Update:
It seems to be some kind of bug the Hibernate team had to fix. In my case the logic is extremely trivial, I cannot believe Hibernate unable to update current entity. There has to be a way.