In Lazy loading, you load the child data as and when required.
Example:
public class OrderBean implements EntityBean {
private long orderId;
private String orderName;
private long lineItemId; // FK to the child table LineItems table
private Collection lineItems; // child data from LineItems table
public void ejbLoad() {
// step1: select orderId, orderName and lineItemId from Order table
}
public Collection getLineItems(){
/* step2: get lineItems by looking up LineItem entity bean
: look up LineItem home reference through JNDI
lineItems = lineItemHome.findLineItems(lineItemId);
*/
return lineItems;
}
Here you load the data as and when client calls getLineItems() but not when it calls other business methods. So Lazy loading is best to improve performance and use it when you implement relationships in Entity beans.