• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Child Records - When to load?

 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic