EJB QL question for CMP with relationships

Discussions

EJB programming & troubleshooting: EJB QL question for CMP with relationships

  1. EJB QL question for CMP with relationships (4 messages)

    Can you do a findBy from the "end" bean in a unidirectional relationship?

    For example:
    Give me the "state bean collection" for all states that have a location.

    So a Location bean has an Address bean that has a State bean.

    In sql it would be "SELECT DISTINCT STATE.STATE_ID WHERE LOCATION.ADDRESS_ID = ADDRESS.ADDRESS_ID AND ADDRESS.STATE_ID = STATE.STATE_ID"

    Is this possible in EJB-QL?

    Thanks



  2. EJB QL question for CMP with relationships[ Go to top ]

    you should use "ejbSelect" instead "find" method if you want to make this ejb-ql work.
  3. EJB QL question for CMP with relationships[ Go to top ]

    Sorry,I misunderstood your meaning.

    You can use "astract-schema-name" which you defined in your ejb-jar.xml for each cmp bean, to make your query.
  4. EJB QL question for CMP with relationships[ Go to top ]

    The problem is that it is on the wrong end of the unidirectional relationship.

    The "State Entity" does not know about the address/location.

    Is there a way to get a state collection relating back up the chain?
  5. Try this:

    SELECT DISTINCT OBJECT(loc.address.state)
    FROM Location loc

    This finds all the locations, and get's the state associated with the address associated with the location.

    Gal