DAO Pattern- Lazy initialization of OneToMany-Relation
Hi
I have 2 classes, Order and OrderItem. An Order can have one or more OrderItems.
Further i have written two DAO's for the mentioned entites, OrderDAO and OrderItemDAO.
For several reasons i want to lazy initialize the relationship:
publicclass Order{
/**
* Getter for the OneToMany-relation to <code>OrderItem</code>.
*
* @return Array of <code>OrderItem</code>-objects
*/
public OrderItem[] getOrderItems(){
// Lazy load
if (this.orderItems ==null){
this.orderItems =
OrderItemDAO.loadAllByOrderId(this.orderId);
}
return this.orderItems;
}
}
My simple question is, if this approach is correct? Is it appropriate that i can call the OrderItemsDAO from an Order-instance? Or do i have to delegate the reading of the OrderItems first to OrderDAO and from there finally delegate it to the OrderItemDAO?
Kind regards
Michael

