Use @PrimaryKeyJoinColumn

http://www.java2s.com/Tutorials/Java/JPA/0730__JPA_OneToOne_Primary_Key_Join.htm



@Entity

public class Person {

  @Id

  @GeneratedValue(strategy=GenerationType.IDENTITY)

  private long id;

   
  private String name;
  @OneToOne

  @PrimaryKeyJoinColumn
  private Department department;
  

when you want to use Person's id to join with Department's id

If in Person entity have a FK with name "departmentID" then you should use @JoinColumn


Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch