JPA - CascadeType.REMOVE after entity is deleted by orphanRemoval = true

2
public class PrimeiroNivel {  

   @OneToMany(mappedBy="primeiroNivel", orphanRemoval=true)  
   private List<SegundoNivel> niveisSecundarios;  
}

public class SegundoNivel {  

    @JoinColumn(name="primeirNivel")
    @ManyToOne  
    private PrimeiroNivel primeiroNivel;  

    @JoinColumn(name="outraClasse")
    @ManyToOne(cascade={CascadeType.ALL})  
    private OutraClasse outraClasse;
}

public class OutraClasse {

    @OneToMany(mappedBy="outraClasse")  
    private List<SegundoNivel> segundosNiveis;
}

Considering the classes and annotations above:

instanciaDePrimeiroNivel.setNiveisSecundarios(null);

Does anyone know why the above line excludes the secondary levels that were present in the First Level instance list (orphanRemoval expected behavior), but does not delete the associated OtherClass instances at these excluded levels (which are marked for cascading exclusion)?

CascadeType.REMOVE does not work if you do not use the entityManager.remove (Object)?

Is there any workaround to resolve this situation?

    
asked by anonymous 24.07.2018 / 20:10

0 answers