@ Data
@ the Entity
Public class Department {
@ Id
@ GeneratedValue (strategy=GenerationType. IDENTITY)
Integer id;
String code;
String name;
The String location;
@ OneToOne (mappedBy="department", cascade={CascadeType CascadeType. PERSIST, MERGE, CascadeType. REFRESH})
Leader Leader.
}
@ Data
@ the Entity
Public class Leader {
@ Id
@ GeneratedValue (strategy=GenerationType. IDENTITY)
Integer id;
String code;
String name;
@ OneToOne (cascade={CascadeType. ALL})
Department Department;
}
The last query output foreign key table which content is empty