Hi everyone,
I am trying to think of the most efficient way to list data on the client
end (html) that is the result of a "join" in between two EJB's.
ie: suppose I have a page that lists details about cars. In the backend
I have a car entity bean, and a car manufacturer entity bean. The two are
connected by a manufacturer foreign key stored in the car entity bean.
Now I want the web page to list each car and the "name" of the
manufacturer.
Since I am using info/details objects to pass entity bean data to the
servlets (via a facade session bean), the info bean that gets passed to the
JSP contains only the primary key of the manufacturer, not its "name".
One solution to this problem is to go the ultra-efficient way and ignore
my entity bean model alltogether and do a SQL join to return what I need
from a method in a session bean. Being the object purist that I am I would
rather not ignore my nice object oriented entity bean model like this.
The other solution is that in my session bean facade, I can get all the
cars I want, and for each car get the info/details bean for its corresponding
manufacturer bean and pass the whole thing back to the servlets. I don't
like this because it essentially results in n^2 database calls just to list
a simple web page, and passing two separate enumerations of beans that should
really be connected in some way seems clumsy.
Another solution is to create a new data bean called "carAndManufacturerInfo",
and populate it in the same manner as in the last option, and pass that to
the servlets. This is cleaner for the servlets but still n^2 calls to the DB.
A much faster solution is to anticipate that listing cars with a manufacturer
name is a common thing, so just throw the manufacturer name into the car
entity bean, to remove the extra searches required to get at it.
I hate this solution even more as it violates encapsulation, but would result
in O(n) calls for this usecase.
This must be a common enough usecase in J2EE programming that someone must
have thought of this before, can anyone suggest a clean solution to this
problem?
thanks in advance,
Floyd
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".