I have below JPA Tables. I have used uni-directional OneToMany relationship.
@Entity
@Table(name = "xxx")
public class Parent {
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "Child_ID")
private Set<Child1> child;
//getter setters
}
@Entity
@Table(name = "xxx")
public class Child {
//other colmns
//getter setters
}
When I first add entries to above parent Set(say 20) and save(), it saves to database successfully. Then In same set I have added 10 more and called save method. It save 10 new to db. If I again call save it add same 10 more to database again creating duplicate entries.
Parentrepository.save(parentObject);