I have an entity called Order, which has an attribute that is a List of LineItem objects. When I persist an order, I would like the line item objects it contains to be persisted as well. How can I do this? I tried to set the cascadeType for the List to a cascade type of ALL, but that causes a constraint violation. I tried to then use MERGE, but that didn't add anything to the LineItem table. Any ideas?
public class Order {
...
@OneToMany(mappedBy = "order")
private List<LineItem> orderSegments;
...
}
public class LineItem {
...
@ManyToOne
@JoinColumn(name="ORDER_ID")
private Order order;
...
}
When I persist an Order, for some reason, nothing gets put into the line item table