1 Reply Latest reply on May 25, 2002 9:05 AM by butlerca

    CMP 2.0 design question

    morphace

      Hi all,

      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) ?

      TX

        • 1. Re: CMP 2.0 design question
          butlerca

          I am a little new to CMP 2.0, so take my advice with a grain of salt. In CMP 2.0 you can specifiy relationships with other entities in the ejb xml file. If you define a one to many relationship with customer and invoice, the container should manage that for you. I do not remember the specific tag you use for relationships, but you do have to change your interface as well to provide an access to the relational data.