1 Reply Latest reply on Aug 7, 2003 11:20 AM by manri

    Relation Problem with composite pk

    manri Newbie

      Hi there,

      I am struggling with a relation which looks like this:

      - CMP 2.0

      User Bean:
      id: pk field
      name: name of the user
      ... and other fields ...

      Bookmark of a User (Bookmark Bean):
      user_id: is the primary key of the user (User.id)
      url: a url which the user wants to bookmark
      description: description of the url


      Since it doesn't make sence, that a User has duplicate bookmarks (bookmarks with the same urls). I created a composite pk with (user_id, url). So a Users Bookmarks will always be distinct in the "url"

      Now I want to set a relation between the User and the Bookmark, so I can do something like this:

      Collection collection = user.getBookmarks();

      when I set the relation fields and columns in jbosscmp-jdbc.xml, I thought I only have to describe the relation between "User.id" and "Bookmark.user_id" (foreign-key-mapping). But since Bookmark has a composite pk the Deployer always wants me to specifiy the "url" field as well. Why is this neccessary? If I do specify the "url" field, JBoss creates another table to map the "User.id" field to the composite pk. This doesn't look very efficient to me, because the relation should be clear without that extra table (at least for me) ...

      Is there a way to set the relation in a different way?


      manri