I'm just starting to use Hibernate and I was wondering how to insert a new element into a oneToMany relation without loading the container first.
Consider the following example:
@Entity
@Table(name="orders")
class Order {
@Id @GeneratedId
public Long id;
@OneToMany(mappedBy="order")
public List<Item> items = new ArrayList<Item>();
}
@Entity
@Table(name="items")
class Item {
@Id @GeneratedId
public Long id;
@ManyToOne
public Order order;
}
I want to insert a new Item into an Order (I know the order's id and that it is valid), but I do not want to load the order first. Clearly, this should be possible, as the SQL only needs the id for the insert and not the entire Order object.