I have a design question concerning the retrieval of entities thru EJB-QL.
I need to develop a flexible way to retrieve some entities and their associated entities, which results in a (value)object graph.
Everyone would say: issue a EJB-QL query on the master entities and then access the associated entities with their cmr accessors.
The problem is, that I want to select SPECIFIC master and associated entities. For example:
All customers whose name begin with 'M' (like 'Microsoft' :-() and the associated invoices with an amount greater than $1000.
Sure, it's no problem to write an EJB-QL query, which returns the appropriate customer entities.
But I have to retrieve the invoice entities too. If I use the cmr accessors, I'll get all the invoices, not only those with an amount greater than $1000.
So finally, my question is how to design this stuff optimally, considering, that I'm developing a general purpose framework for business apps, which has to handle arbitrary EJB's.
Is it better to write a method, which filters the associated entities (which is quite "hard coded", or should I use ejbSelect methods (which would be more flexible) ?
I would use several ejb select methods as these are much more efficient the walking the object graph. You will have to find some way to assemble the final results. Also you may need to use dynamic-ql to get the exact queries you need.