0 Replies Latest reply on Sep 14, 2003 6:52 AM by Corey

    CMR Problem

    Corey Newbie

      Hello,

      I'm new to JBoss/J2EE so this probably a dumb question but anyway.. Here's the scenario I have two entity beans UserBean and GroupBean. There is a many to many bidirectional relationship between these two beans. Here's the CMR declaration for UserBean:

      /**
      * Groups User is in
      *
      * @ejb.persistent-field
      *
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="UsersInGroupsRelation"
      * role-name="UserInGroups"
      * target-role-name="GroupHasUsers"
      * target-cascade-delete="no"
      *
      * @jboss.relation
      * related-pk-field="id"
      * fk-column="userId"
      */
      abstract public Collection getGroups();

      Here's the CMR declaration for GroupBean:

      /**
      * Group's Users
      *
      * @ejb.persistent-field
      *
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="UsersInGroupsRelation"
      * role-name="GroupHasUsers"
      * target-role-name="UserInGroups"
      * target-cascade-delete="no"
      *
      * @jboss.relation
      * related-pk-field="id"
      * fk-column="groupId"
      */
      abstract public Collection getUsers();

      I then have a test servlet where I create a user then create a group:


      context = getInitialContext();
      groupHome = (GroupHomeLocal)context.lookup("GroupHomeLocal");
      userHome = (UserHomeLocal)context.lookup("UserHomeLocal");
      user1 = userHome.create("first1", "middle1", "last1");
      group1 = groupHome.create("group1");

      This code seems to work both the user and group are created. The problem is that after this I attempt to add the user to the group:

      users = group1.getUsers();
      users.add(user1);

      For some reason the users Collection returned from group1 is null. Can anyone tell me what I'm doing wrong.