Answer the question
In order to leave comments, you need to log in
How to implement OneToMany communication?
I have a product class:
@Entity
public class Product {
set<Category> categories;
}
@Entity
public class Category {
//...
}
Answer the question
In order to leave comments, you need to log in
@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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question