1 Reply Latest reply on Jan 15, 2004 9:01 AM by sbrbot

    How to retrive foreign key values from a 1-N relation?

    ericpf

       

      "ericpf" wrote:
      Need help in order to retrive the foreign key values from a 1-N relation.
      I have 2 tables, User and Friend, where a User can have many Friends.
      The User table has id as PK, while the Friend table has id as PK and userId as FK.
      The issiue is that I need to pick out instances of Friend that match a certain userid, so I somehow need to reference the foreign key column.
      Corresponding to the 2 tables, I have a UserBean and a FriendBean, both of which are CMP's. I'm also using X-Doclet to generate interfaces, etc.

      So far I've been able to get ahold of instances of FriendBean, but these do not include the FK-column. I've also tried using a finder-method in the UserBean, along these lines:

      @ejb.finder
      signature = "Integer findByFriendId
      ( java.lang.Integer userid ) "
      query = "SELECT OBJECT(a) FROM User a WHERE a.Friend.id = ?1"
      result-type-mapping = "Local"

      This didn't work either. Can anyone help me out on this one?