File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Child Records - When to load? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Child Records - When to load?" Watch "Child Records - When to load?" New topic

Child Records - When to load?

Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
Say I've got two tables with matching Java Beans. We'll call them Order and OrderItem. The Order bean contains a Collection which holds all OrderItem beans of that order which is modeled in the DB as a One to Many.
My question is should not the developer know exactly when they will need only the Order bean and when they will need both the Order and OrderBean collection populated? Loaded the Order bean with the Collection populated is an added cost and if I do not yet need it, why do it?
The reason I ask is we are currently reevaluating how our DB access should be handled. One of the leading candidates is a tool that determines when to load the children for you. So, if I only load the Order, the OrderItem Collection will not be populated until I try to access it (I can also force an init of the Collection which will do this). Since this 'hides' when the data is loaded and there is no longer a need for an explicit load of this data, I wonder if this is good practice. If I load an Order in a Servlet and forward to a JSP which shows the OrderItem collection, this method of loading the children will do it for us at the JSP level, which breaks the strict MVC (JSP being the View) model.
Any opinions and comments are requested.
I agree. Here's the link:
subject: Child Records - When to load?
It's not a secret anymore!