0
Is there any way defined by JPA that prevents the exclusion of a parent object if it has a child object attached to it? For example:
I have the class (Entity) Department, in which I have the following field:
@OneToMany(mappedBy = "departamento" )
public List<Usuario> getEmpregados() {
return empregados;
}
The field employees is a list of employees linked to this Department.
I need that when requesting the exclusion of a department, this action does not occur if you have any employee linked to it.
Analyzing the JPA Cascade Type, I did not find any option that makes this lock, the solution I see is to do the validation manually before executing the Jparepository delete command for the Department.
Is there any way that JPA can enforce the integrity of the bank and prevent a parent object from being excluded by having children attached, something like an annotation?