0

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.

Aniruddh Parihar
  • 2,674
  • 2
  • 19
  • 34
  • Does this answer your question? [PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate](https://stackoverflow.com/questions/13370221/persistentobjectexception-detached-entity-passed-to-persist-thrown-by-jpa-and-h) – M. Dudek Aug 05 '21 at 12:50

0 Answers0