I have a hierarchical data structure (using Entity beans)like say a Book Class which has a Book ID and references to a bunch of Chapter classes.And each chapter class has a Chapter number and references to a number of Page classes. In my Display class, I would like to display the book id of a Book object.
But when I call getBook() , the existing code loads up the chapters and pages too, even though I just want to get only the Book ID from the Book object.This is resulting in heavy database querying.
I am looking for a design pattern to solve this problem.Any ideas guys?
You should use lazy loading design pattern.
Here is a good example.
http://www.precisejava.com/javaperf/j2ee/EJB.htm#EJB133