@Entity
public class Product {
set<Category> categories;
}
@Entity
public class Category {
//...
}
@Table(name="parent")
class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private Set<Child> attachments = new HashSet<Child>();
.....
}
@Entity
@Table(name="child)
class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "parent_id", nullable = false)
private Parent parent;
...
}
@Entity