title: JPA: @PrimaryKeyJoinColumn or @JoinColumn + @Id
body: <p>I have user class with @Entity annotation.</p>
  
  <pre><code>@Entity
  public class User{
  
  @Id
  @GeneratedValue
  private Long id;
  
  private String firstName;
  private String lastName;
  
  }
  </code></pre>
  
  <p>And i need to create another table with User details.
  It must be linked to User_id and don't have it's own id just:
  <code>user_id</code> <code>phone_number</code> <code>address</code></p>
  
  <p>So, now i use this:</p>
  
  <pre><code>@Entity
  @Table
  @Data
  public class UserDetails{
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(nullable = false)
      private Long id;
  
      @OneToOne (fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      @PrimaryKeyJoinColumn
      private User user;
  
      private String address;
      private String phone;
  }
  </code></pre>
  
  <p>But i have a question: Why i use this:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(nullable = false)
  private Long id;
  </code></pre>
  
  <p>if </p>
  
  <pre><code>@OneToOne (fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  @PrimaryKeyJoinColumn
  private User user;
  </code></pre>
  
  <p>makes user_id for me?</p>
  
  <p>If i delete Id field i have an error: No identifier specified for entity: test.UserDetails, but hey! @PrimaryKeyJoinColumn creates identifier for this entity.</p>
  
  <p>Maybe i should use @Id + @JoinColumn instead of @PrimaryKeyJoinColumn?</p>