I have Entity classes like following:
@Entity
@Table(name = "PARENT")
public class Parent {
@OneToMany(mappedBy = "parent")
private List<Child> childs;
}
and
@Entity
@Table(name = "CHILD")
public class Child {
@ManyToOne
@JoinColumn(name = "PARENT_ID", referencedColumnName = "ID", insertable = false, updatable = false)
private Parent parent;
}
In my code, when I am trying to save a Child the Parent is also getting saved:
Parent parent = parentRepository.findOne(id);
//Code which changes parent attributes
child.setParent(parent);
childRepository.save(child);
I have not used parentRepository.save()
, any cascade. And insertable
, updatable
is also set to false
.
Is it happening because parent object is attached to context for parentRepository.findOne(id);
call? How to avoid this?
PS: I am using spring-boot 1.5.9, Spring Data