Let's say I have Person
and Order
entities in a uni-directional, one-to-many
relationship.
Person
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(mappedBy = "person")
Set<Order> orders = new HashSet<Order>();
// other fields, constructor, setters and getters
}
Order
@Entity
public class Order {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "id")
Person person;
// other fields, constructor, setters and getters
}
How can I update a Person
's Set<Order>
with new Order
's?
Do I need to do something like:
Order o = new Order();
// ???
person.setOrders(new HashSet<Order>(o));
Since Person
has a OneToMany
relationship with Order
's, I'm not sure how to set a Person
's orders
.