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

[1407 byte] By [jmw71a] at [2007-11-26 13:55:36]
# 1
Hi,my opinion is that you might delegate to OrderDAO the entire work regarding an order object.Fil
fmagrini72a at 2007-7-8 1:34:44 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Where are these DAOs coming from? Are they generated?I Wonder why you need all this delegation.
gewittera at 2007-7-8 1:34:44 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
I have simply one DAO per entity. They are generated by a generator, but we could easily implement them "by hand"...
jmw71a at 2007-7-8 1:34:44 > top of Java-index,Other Topics,Patterns & OO Design...