One of the solution could be:
We will update Employee POJO as below
Code:
ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "DEPARTMENT_ID", referencedColumnName = "DEPARTMENT_ID", **insertable=false, updatable=false**)
private Department department;
@Column(name = "department_id")
private Long departmentId;
(both department and departmentId will have setter and getter methods)
and Now here (please see that both department and departmentId mapped to same column (DEPARTMENT_ID)
we use
department only for fetching Department details
and
departmentId to insert or update
Employee But I am worried if it is a better approach.