In my Employee class I have the following field:
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private Set < EmployeePositionOrgUnit > employeePositionOrgUnits;
In EmployeePositionOrgUnit class I have the following fields:
@ManyToOne
@JoinColumn(name = EMPLOYEE_POSITION_ORGUNITS_EMPLOYEE_ID)
private Employee employee;
@ManyToOne
@JoinColumn(name = EMPLOYEE_POSITION_ORGUNITS_POSITION_ID)
private Position position;
@ManyToOne
@JoinColumn(name = EMPLOYEE_POSITION_ORGUNITS_ORGUNITS_ID)
private OrganizationalUnit organizationalUnit;
When saving a new Employee with employeePositionOrgUnits, I get the following transaction error:
detached entity passed to persist -> Organizational Unit.
When saving an already existing Employee, the problem doesn't occur.
I would like to know if there is a way to save the new Employee, while still being able to remove the EmployeePositionOrgUnits from the Employee.