title: How persist with Hibernate
body: <p>I have a class named "Token Requestor" and "Certificates". Each Token Requestor have many Certificates and Certificates have <strong>only one</strong> Token Requestor.</p>
  
  <p>TokenRequestor.java</p>
  
  <pre><code>@Entity
  @Table(name = "TOKEN_REQUESTOR")
  public class TokenRequestor implements Serializable {
  
      @Id
      @SequenceGenerator(name = "TOKEN_REQUESTOR_ID_GENERATOR", sequenceName = "TOKEN_REQUESTOR_ID")
      @GeneratedValue(strategy = GenerationType.AUTO, generator = "TOKEN_REQUESTOR_ID_GENERATOR")
      @Column(name = "TOKEN_REQUESTOR_ID")
      private Long id;
      @OneToMany(mappedBy = "tokenRequestorId")
      private List&lt;Certificate&gt; certificates;
  </code></pre>
  
  <p>Certificate.java</p>
  
  <pre><code>@Entity
  @Table(name = "CERTIFICATES")
  public class Certificate {
  
      @Id
      @SequenceGenerator(name = "CERTIFICATES_ID_GENERATOR", sequenceName = "SQ_CERTIFICATES_ID")
      @GeneratedValue(strategy = GenerationType.AUTO, generator = "CERTIFICATES_ID_GENERATOR")
      @Column(name = "CERTIFICATES_ID")
      private Long id;
      @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
      @JoinColumn(name = "TOKEN_REQUESTOR_ID")
      private TokenRequestor tokenRequestorId;    //Foreign key*/
  </code></pre>
  
  <p>When I insert a Token Requestor, they certificate must be create. They are created but with TOKEN_REQUESTOR_ID null in Certificate table. Why this happens?</p>
  
  <p>POST Token Requestor</p>
  
  <pre><code>{
      "domain": "GTW",
      ...,
      "certificates": [
      {
        "usage": "ENC",
        "alias": "encryption_cert",
        "content": "-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----"
      },
      {
        "usage": "DEC",
        "alias": "decryption_cert",
        "content": "-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----"
      },
      {
        "usage": "SSL",
        "alias": "communication_cert",
        "content": "-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----"
      },
      {
        "usage": "CA",
        "alias": "TSP ROOT CA",
        "content": "-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----"
      }
    ]
  }
  </code></pre>