title: No part of a composite indentifier may be null
body: <p>I'm trying to make a <strong>composite primary key mapping</strong> and doesn't work.</p>
  
  <p><strong>The requisites are:</strong></p>
  
  <ul>
  <li>The relation may be with <code>@IdClass</code> annotation</li>
  <li>I need the relationship with person entity be <code>@ManyToOne</code></li>
  </ul>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>@Entity
  @IdClass(PhonePK.class)
  public class Phone implements Serializable{
      @Id
      @Column(name = "codigo", nullable = false)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long code;
  
      @Id
      @ManyToOne
      @JoinColumn(name = "person", referencedColumnName = "code", nullable = false)
      private Person person;
  
      @Basic
      @Column(name = "number", nullable = false)
      private Integer number;
  
      //getters and setters
      //equals and hashcode
  }
  
  public class PhonePK implements Serializable {
      private Long code;
      private Long person;
  
      public PhonePK(){}
  
      public PhonePK(Long code, Long person) {
          this.code = code;
          this.person = person;
      }
  
      //getters and setters
      //equals and hashcode
  }
  
  public class Person implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "code", nullable = false)
      private Long code;
  
      //getters and setters
      //equals and hashcode
  }
  </code></pre>
  
  <p><strong>They way I'm trying to persist:</strong></p>
  
  <pre><code>//a lot of code
  //em = Entitymanager
  em.persist(person);
  phone.setPerson(person);
  em.persist(phone);
  </code></pre>
  
  <p><strong>The error that I'm receiving is:</strong></p>
  
  <blockquote>
    <p>Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: No part of a composite identifier may be null</p>
  </blockquote>