I think this issue has been discussed a lot here. It is my feeling that you
should have a stateless session bean (let's call it "joinqueries" bean)
which will do all the queries for your application where joining tables is
involved.

Customer is an entity, address is an entity, customerAddress is definitely
not an entity IMHO. There is no persistance of any sort involved in select
queries. So I can't think of any reason to use entity beans (CMP or BMP). We
have got somehow misled (by ourselves) that anything that has to do with a
database has to be an entity bean.

What you need for join queries is a read-only stateless session bean. The
negative thing about it is that your bean is now expecting a particular
schema. In my case here, we want to address different databases/j2ee servers
but our DB schema is not expected to change much (hopefully :). But anyway,
as all the join queries come from one particular "joinqueries" bean, only
the code for that bean needs to be changed in case there is change in
underlying DB schema.

Subu Vdaygiri

> -----Original Message-----
> From: Al Fogleson [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 16, 2000 4:09 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Object-relational problem
>
>
> As compared to the network overhead of multiple bean calls and their
> inherent calls to the database? I end up with this battle
> with a fellow
> developer at work all the time who seems to think, if it is
> in a database
> table it has to be an entity bean... Not so say I :)
>
> the other option would be to code the SQL such that it
> returns that whole
> congomeration in a findAllCustomers method, with one SQL call
> I guess. BMP
> would probably be the way to go on this. (IMHO)
>
> ----- Original Message -----
> From: Tim Fox <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, May 18, 2000 12:18 PM
> Subject: Re: Object-relational problem
>
>
> Umm..
> It seems you're suggesting doing a table join in code.
> I've always thought this practice somewhat dangerous - you're
> essentially
> competng with programs like Oracle which specialise in doing this.
> May work for a simple join on two tables, but what about 3 or 4 ?
>
> Al Fogleson wrote:
>
> > Nothing says that the address has to be an EJB. :)
> >
> > You could make the address a class and have it grab all the
> addresses from
> > the database, then in the customer bean you can match the
> address with the
> > customer using the PK and FK relationship. if you further
> implement the
> > address class as a singleton it can retain the result set
> over multiple
> > instances of the Entity bean. In your case I would likely use a
> > findAllCustomers, and spit that back to the rendering
> engine to put on the
> > web page. makes for 2 database calls, one to get all the
> customers, and
> one
> > to fill the address class.
> >
> > Al
> >
> > ----- Original Message -----
> > From: Tim Fox <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, May 18, 2000 11:17 AM
> > Subject: Object-relational problem
> >
> > Here's a problem I've been chewing over for a while now and
> haven't come
> > up with a satisfactory solution.
> > It's one of the classic object-relational problems.
> >
> > Here's a simplified description (please note that this is a
> fictitious
> > example - I've simplified it for clarity)
> >
> > I have 2 ejbs: a Customer and an Address.
> > The customer has a home address.
> >
> > I'm displaying a list of all customers satisfying certain
> criteria along
> > with their home address on a web-page.
> >
> > There would be one customer & address per line.
> >
> > This would look something like:
> >
> > Customer Name            Customer Address
> > ===========            =============
> > Joe Bloggs                    1 High Street, Newtown
> > John Doe                      23 Synchronicity drive, London
> > Jane Doe                      2 Big Street, Badville
> >
> > Now the page is hit a lot so I want to get the entire list using one
> > query - this is pretty easy in SQL - a simple join across
> the customer
> > and address tables.
> >
> > The last thing I want to do is query for all the customers,
> then, for
> > each customer query for the address - this would cripple the system
> > since I'd have a new query for each row of the page.
> >
> > However, if I'm using ejb then it seems I could either:
> > 1.
> > Use a finder method to get the list of customers given the criteria,
> > then...
> > For each customer in the list, use the findByPrimaryKey()
> (or whatever)
> > method to find the address.
> > This is probably the worst solution since it would probably
> involve a db
> > query for each customer address.
> >
> > 2.
> > Use a finder method to get the list of customers given the criteria,
> > then...
> > Use a finder method to get the list of addresses given the criteria.
> > This basically involves running the same (or very similar)
> query twice -
> > once in the Customer finder method, and once in the Address finder
> > method.
> > This, although better than 1) seems very wasteful
> >
> > 3.
> > Do the query once, and pass the resultset into the finder
> methods of the
> > customer and address objects - don't know if this is
> possible though due
> > to remote calls and marshalling of the resultset
> >
> > 4. Create a denormalised ejb called AddressCustomer which is an
> > amalgamation of the Address and Customer objects. Yuck!!!
> > Then I also end up with an AccountCustomer,
> AccountCustomerStatement,
> > ProductManufacturerSupplier etc. ad infinitum objects.
> > Basically the nice OO model gets shot to f*** !!
> >
> > I'd been interested in any comments/solutions people have
> implemented,
> > as this is really bugging me
> >
> > (BTW if I wasn't using ejb I'd use 3) since I wouldn't have
> any remote
> > calls problems).
> >
> > Cheers
> >
> > --
> > Tim Fox (��o)
> >
> > Senior developer
> > Hyperlink plc
> > http://hyperlink.com
> >
> > email: [EMAIL PROTECTED]
> > phone: +44 (0) 207 240 8121
> >
> >
> ==============================================================
> =============
> > 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".
> >
> >
> ==============================================================
> =============
> > 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".
>
> --
> Tim Fox (��o)
>
> Senior developer
> Hyperlink plc
> http://hyperlink.com
>
> email: [EMAIL PROTECTED]
> phone: +44 (0) 207 240 8121
>
> ==============================================================
> =============
> 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".
>
> ==============================================================
> =============
> 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".
>

===========================================================================
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".

Reply via email to