1

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.

J.Olufsen
  • 13,415
  • 44
  • 120
  • 185

1 Answers1

1

Fixed it by removing CascadeType from source entity.

Sarang
  • 669
  • 1
  • 7
  • 12