Parent.java:
Code: Select all
@Entity
public class Parent {
@Id
private Integer id;
@OneToMany(mappedBy = "parent")
private List childs = new ArrayList();
...
Code: Select all
@Entity
public class Child {
@Id
private Integer id;
@ManyToOne
@JoinColumn(name = "parent_id")
private Parent parent;
...
Code: Select all
Parent parent = new Parent(1);
Child child = new Child(1);
Child child2 = new Child(2);
child.setParent(parent);
child2.setParent(parent);
parent.getChilds().add(child);
parent.getChilds().add(child2);
parentRepository.save(parent);
Code: Select all
Unable to find Child with id 1
Mobile version