I have an Entity with a collection of child Entities:
Code:
@Entity
public class Client{
...
@OneToMany(mappedBy="client",cascade=CascadeType.ALL)
@JoinColumn(name="CLIENT_ID")
public List<CarOrder> getOrders(){
return orders;
}
...
}
Now I want to create new orders and add it to client entity from java without detaching it.
In my business component I have variable `orders' where I accumulate orders that are being added by user before really adding them to client entity. Finally I want to add all orders entered by user to relationships collection on entity class, but whether I do it this way:
Code:
public void addOrders(){
client.getOrders().addAll(orders);
}
or this way:
Code:
public void addOrders(){
client.setOrders(orders);
}
Or some other ways client entity is detached and even calling entityManager.merge(client) doesn't help (entityManager.contains(client) still returns false) - and I want to keep it persisted. What is the best way to add child entitities to to parent entity? Thanks in advance.