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

Asked

Viewed 88 times

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 above classes and annotations:

instanciaDePrimeiroNivel.setNiveisSecundarios(null);

Does anyone know why the line above excludes the secondary levels that were present in the instantiation listDePrimeiroNivel (expected orphanRemoval behavior), but does not exclude the instances of Outraclasse associated in those excluded levels (which are marked for cascade exclusion)?

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

Is there any alternative solution to resolve this situation?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.