title: Hibernate: a different object with the same identifier value was already associated with the session
body: <p>I did see all other similar questions but none of the solutions solves my problem.</p>
  
  <p>I have two classes: Person and PersonSynonym. A person can have many synonyms. The synonyms property in the Person class looks like this:</p>
  
  <pre><code>@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  @JoinColumn(name = "person_id")
  private Set&lt;PersonSynonym&gt; synonyms = Sets.newHashSet();
  </code></pre>
  
  <p>and the PersonSynonym class:</p>
  
  <pre><code>    @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      private String name;
  ... (getters, setters, equals, hashcode, ...)
  </code></pre>
  
  <p>updating the Person objects works fine if I'm adding only ONE synonym to a person. As soon as I try to add a second synonym and try to update the person object I'm getting this exception:</p>
  
  <pre><code>Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [my.package.model.PersonSynonym#6]
  </code></pre>
  
  <p>the synonym with the id 6 is the one existing already. Apparently hibernate tries to insert the existing one again... why?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>moving the JoinColumn to PersonSynonym doesn't help, Person:</p>
  
  <pre><code>@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "person_id")
  private Set&lt;PersonSynonym&gt; synonyms = Sets.newHashSet();
  </code></pre>
  
  <p>PersonSynonym:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  
  private String name;
  
  private Long person_id;
  
  @ManyToOne
  @JoinColumn(name = "person_id", referencedColumnName = "id", insertable = false, updatable = false)
  private Person person;
  </code></pre>