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

Discussion in 'Java' started by Eric Ford, Jan 14, 2004.

  1. Eric Ford

    Eric Ford Guest

    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?
    Eric Ford, Jan 14, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    338
    Ratman
    Jun 23, 2004
  2. Replies:
    2
    Views:
    425
  3. H5N1
    Replies:
    0
    Views:
    430
  4. Raymond Schanks
    Replies:
    0
    Views:
    643
    Raymond Schanks
    Aug 3, 2010
  5. Lionel
    Replies:
    9
    Views:
    3,368
Loading...

Share This Page