Parent Entity
Employer (parent)
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name = "name")
private String name;
@OneToMany( mappedBy = "employer",
cascade = CascadeType.ALL,
orphanRemoval = true)
private List<Employee> empDetails = new ArrayList<>();
Employee (child)
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
@ManyToOne(optional = false,fetch = FetchType.LAZY)
@JoinColumn(name="emp_id", referencedColumnName = "id")
private Employer employer;
Json from postman
{
"name" : "data",
"empDetails":[{
"firstName" : "ttest",
"lastName" : "te"
}]
}
I'am trying to save in single save call like. Once parent is saved then child will be persisted automatically . But while doing so parent reference in child column is inserted with null.