Home > other >  How do you use the JPA one-to-one mappedBy
How do you use the JPA one-to-one mappedBy

Time:09-26

@ 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
  • Related