I read about the error in title but I can't find suitable solution for my case, I have the following relation :
@Entity
public class Parent {
@OneToMany(fetch = FetchType.EAGER,mappedBy = "parent",cascade = CascadeType.MERGE)
@Fetch(FetchMode.SUBSELECT)
private List<Child> child;
}
@Entity
public class Child {
@EmbeddedId
@JsonIgnore
private CompositePK compositePK;
@MapsId("compositeId")
@ManyToOne
@JoinColumn(name = "PARENT_ID")
@JsonIgnore
private Parent parent;
@MapsId("AId")
@JoinColumn(name = "A_ID")
@OneToOne
private A a;
}
I don't have a transnational over my method and no open sessions , the following line throws error when trying to merge parent and merge its Child entites: parent= parentRepository.save(parent);
A different object with the same identifier value was already associated with the session : [....CompositePK@22bf8646]; nested exception is javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : .......CompositeMedicinePK@22bf8646]"
any explanation ?