2 Replies Latest reply on Apr 17, 2004 7:02 PM by Micah Spears

    EJB-QL query for selecter in n:m relation??

    null null Newbie

      Hi everybody,

      If I made an unidirectional n:m relationship between, let´s say, a CustomerBean and a AddressBean bean (customer has a getter and a setter for his addresses). The mapping is made by a relational table. Both beans work. And after that I want to implement an ejbSelectStreets method (without parameters) to get all streets of a certain customer. What should the ejbQuery look like?

      I tried this:

      public abstract Collection ejbSelectStreets () throws FinderException;

      EJB-QL for this:

      SELECT address.street FROM CustomerAPS AS customer, IN (customer.addresses) as address

      But when I call the ejbSelect-Method in a customer bean, I simply get ALL street entries in the database, not exactly the streets of THIS customer.

      Is it impossible to read the streets without giving the primary key to the selecter? This here works, but seems too complicated to me...

      public abstract Collection ejbSelectStreets (Integer pk) throws FinderException;

      EJB-QL for this:

      SELECT address.street FROM CustomerAPS AS customer, IN (customer.addresses) AS address WHERE customer.id = ?1

      Thanks for your help in advance!
      Oliver