@Entity
@Table(name="parent_table")
public class Parent {
@Id
@Column(name="ID", nullable=false, unique=true)
// Require Generator config
private Long id;
@Column(name="NAME", nullable=false)
private String name;
@OneToMany(orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@JoinColumn(name = "candidacy_id", nullable = false)
@Getter
@Setter
private List<FirstChild> firstChild = new ArrayList<>();
@OneToMany(orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@JoinColumn(name = "candidacy_id", nullable = false)
@Getter
@Setter
private List<SecondChild> secondChild = new ArrayList<>();
}
@Entity
@Table(name="first_child_table")
public class FirstChild {
@Id
@Column(name="ID", nullable=false, unique=true)
// Require Generator config
private Long id;
@Column(name="FIRST_CHILD_NAME", nullable=false)
private String name;
@ManyToOne
@JoinColumn(name="parent_id", referencedColumnName="ID")
private Parent parent;
}
@Entity
@Table(name="second_child_table")
public class SecondChild {
@Id
@Column(name="ID", nullable=false, unique=true)
// Require Generator config
private Long id;
@Column(name="SECOND_CHILD_NAME", nullable=false)
private String name;
@ManyToOne
@JoinColumn(name="parent_id", referencedColumnName="ID")
private Parent parent;
}
And for the repository
@Repository
public interface ParentRepository extends CrudRepository<Parent, Integer> {
}