4 Replies Latest reply on Jul 12, 2004 10:20 AM by Didi

    how to add/remove data from many-to-many CMR?

    Didi Newbie

      Hi,

      I set up a m-n bi-directional CMR relationship with XDoclet (with some little help from http://www.jboss.org/index.html?module=bb&op=viewtopic&t=41050).


      So, my UserEntityBean looks like:

      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name = "user-role"
      * role-name = "user-has-roles"
      *
      * @jboss.relation-table
      * table-name="UserRoleRelation"
      *
      * @jboss.relation
      * fk-column = "fk_rolename"
      * related-pk-field = "rolename"
      *
      * @jboss.relation-mapping
      * style = "relation-table"
      */
      public abstract Collection getRoles();
      public abstract void setRoles(Collection roles);



      and my RoleEntityBean looks like:
      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="user-role"
      * role-name="role-has-users"
      *
      * @jboss.relation-table
      * table-name="UserRoleRelation"
      *
      * @jboss.relation
      * fk-column="fk_username"
      * related-pk-field="username"
      *
      * @jboss.relation-mapping
      * style="relation-table"
      */
      public abstract Collection getUsers();
      public abstract void setUsers(Collection users);



      I think it is working... ok, at least JBoss does not complain while deploying.

      But how do I actually add a Role to a User? And how do I again remove it?
      Can someone provide me with some kind of code example?