title: Hibernate composite id merge
body: <p>I'm using Hibernate with JPA and have a relation like this:</p>
  
  <pre><code>@Entity
  @Table(name = "first")
  public class First {
  ...
  @OneToMany(mappedBy = "first")
  private List&lt;Availability&gt; availabilities;
  ...
  }
  
  
  @Entity
  @Table(name = "second")
  public class Second {
  ...
  @OneToMany(mappedBy = "second")
  private List&lt;Availability&gt; availabilities;
  ...
  }
  
  @Entity
  @Table(name="availability")
  public class Availability implements Serializable {
  @Id
  @ManyToOne
  @JoinColumn(name = "first_id")
  private First first;
  
  @Id
  @ManyToOne
  @JoinColumn(name = "second_id")
  private Second second;
  
  @Column(name = "availability")
  private Integer availability;
  
  ...
  hashcode and equals
  }
  </code></pre>
  
  <p>I want to manage these 3 entities separately. First and Second work fine, but when I try to merge() the third one postgresql gets a null value instead of the id's and constraint violation exception is thrown. Why? Can I even use merge on this entity to add new rows to the table?</p>
  
  <p>update:
  The merge is something like this:</p>
  
  <pre><code>public Availability setAvailability(Availability a) {
  return em.merge(a);
  }
  </code></pre>
  
  <p>where the availability is deserialized from front-end (just to mention, the collections of "key" classes are detached in it).</p>