0

I have two model class:

@Entity
@Table(name = "parents")
public class Parent {

    @Id
    @Column(name="name")
    @Getter
    @NonNull
    private String name;

    @Column(name="lastname")
    @Getter
    private String lastName;

    @OneToMany(mappedBy = "parent")
    @Getter
    private List<Child> children = new LinkedList<>();

}


    @Entity
    @Table(name = "parents")
    public class Parent {

     @Id
     @Column(name="name")
     @Getter
     @NonNull
     private String name;

     @Column(name="lastname")
     @Getter
     private String lastName;   

     @JoinColumn(name = "parentId")
     @ManyToOne
     @Setter
     private Parent parent;

    }

I'd like to auto-save childrens, when I save te parent object. Now, the parents are saving, but no childrens. Now I use Repository<> interface and save(Parent parent) method. What is the solution to this problem?

Bartosz20188
  • 47
  • 1
  • 2
  • 10
  • Possible duplicate of [Save child objects automatically using JPA Hibernate](https://stackoverflow.com/questions/3927091/save-child-objects-automatically-using-jpa-hibernate) – g00glen00b Nov 09 '18 at 14:28
  • Especially the answers from the dupe target that are talking about `CascadeType` are worth looking at. – g00glen00b Nov 09 '18 at 14:28

0 Answers0