I have a mapping as follows:
public class ClasseA {
public ClasseA(){
listaClasseB = new ArrayList<ClasseB>;
}
@OneToMany(mappedBy = "xxxx", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<ClasseB> listaClasseB;
}
public class ClasseB {
@ManyToOne
@JoinColumn(name = "xxxxxxxxxxx", nullable = false)
private ClasseA objetoClasseA;
}
In the method of the service responsible for the rescue:
objetoClasseA.getListaClasseB().add(objetoClasseB);
And persist or merge is only done with objetoClasseA
.
When adding a objetoClasseB
, two records are saved, even with the list containing only 1 element.
What reasons could lead to duplicate records?