3 Replies Latest reply on Sep 23, 2008 11:06 PM by ahmet celik

    multiple foreign key references to same table

    John Degner Newbie

      I've created a small database schema and used seam-gen to generate the entities.  The interesting part of this is the interaction between two tables: users and friends.


      The users table looks like (simplified):
      id,
      name


      The friends table looks like (simplified):
      id,
      ownerid (foreign key to users(id)),
      friendid (foreign key to users(id))


      Everything seems to have been generated correctly.  I have a friends bean with two instances of User, one for the owner and another for friend.  The database updates are functioning correctly as well via seam generated forms.  I think I'm simply having a view problem.


      There's a section of my FriendsEdit.xhtml page that holds a button you can click to navigate to UsersList.xhtml and it's got the following definition:


      <div class="actionButtons">
          <s:button value="Select usersByOwnerid"
                   view="/UsersList.xhtml">
              <f:param name="from" value="FriendsEdit"/>
          </s:button>
      </div>



      It successfully takes me to the Users selction form, and I can select it appropriately.  Upon selection, however, it sets the user for both owner and friend.


      Is there an extra parameter I can send the s:button to tell it that it should select a particular instance variable of the Friends object?

        • 1. Re: multiple foreign key references to same table
          John Degner Newbie

          I know this is a mundane question...and maybe the answer is to just work around this problem by modifying both the FriendsEdit.xhtml view and the UsersList.xhtml view to interact on a more granular level.  I'm a bit at a loss figuring out what exactly to research.  Is it as simple as knowing more about the custom jsf tags?

          • 2. Re: multiple foreign key references to same table
            John Degner Newbie

            Problem solved.  My issue was caused by trying to reference the UserHome object twice in the FriendsHome object.  The Seam Documentation explains how to configure this two ways.  These home objects must be singletons of some sort, so all I had to do was create a OwnersHome object as well as a  FriendsHome object modeled after the generated UsersHome object.  Everything is functioning per design now, with both foreign keys.


            Beautiful work Seam team!

            • 3. Re: multiple foreign key references to same table
              ahmet celik Newbie
              Hi John,
              I am new to seam.
              You are the only one here. I have the same problem with u.
              I would like to ask how did u solve the problem. I downloaded the latest seam version.
              jboss-seam-2.1.0.BETA1( 23/09/2008)

              I have a tables which has 2,3 foreign keys to other same table. In terms of your db,
              The friends table looks like (simplified): id, ownerid (foreign key to users(id)), friendid (foreign key to users(id))
              Friends : id
                        ownerid
                        friendid   generates a java class , with seam generate-entities

              public class FriendsHome extends EntityHome<Friends> {
                      @In(create = true)
                      UserHome userHome;
                      @In(create = true)
                      UserHome userHome;
              .......................

              As I wrote it generates 2fields with same name.So duplicate field. I did correction by hand.But I do not know the rigth strategy. You said everything is fine.Did you generate files correctly. How do u handled this case in Home object.
              Could u tell me how u handled this case,How does your home object look like,how u have generated it.

              Thanks for help..