Parent.java:
Код: Выделить всё
@Entity
public class Parent {
@Id
private Integer id;
@OneToMany(mappedBy = "parent")
private List childs = new ArrayList();
...
Код: Выделить всё
@Entity
public class Child {
@Id
private Integer id;
@ManyToOne
@JoinColumn(name = "parent_id")
private Parent parent;
...
Код: Выделить всё
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);
Код: Выделить всё
Unable to find Child with id 1
Подробнее здесь: https://stackoverflow.com/questions/258 ... g-data-jpa
Мобильная версия