Discussions

EJB programming & troubleshooting: Unidirectional M:N relationship with xDoclet ???

  1. Unidirectional M:N relationship with xDoclet ??? (1 messages)

    Hi,

    I need to add a unidirectional m:n relationship between 2 E.Beans. Can any one help me please..

    I tried with the following stuff

    User and Role Beans are there with the following fields.

    User : userId , password
    Role : name , description

    I need to add roles to users but not viceversa..

    Code snippet for UserBean
    --------------------------
    /**
     * @ejb.interface-method
     * view-type="local"
     *
      *@ejb:relation
      * name="UserAssociatedWithRoles"
      * role-name="UserBeanToRoleBean"
      * cascade-delete="no"
      * target-ejb="Role"
      * target-multiple="yes"
      * target-role-name="UsersHaveRoles"
      *
      * @jboss.relation-table
      * table-name="USER_ROLE"
      * create-table="yes"
           
       * @jboss:relation
       * fk-constraint="false"
       * related-pk-field="userId"
       * fk-column="NAME"
       **/

    public abstract Collection getRoles();

    --------------

    It gives me an error message ---
    <
    But Im using jboss

    --------------

    Can any one help with this..

    Thanks in advance
  2. Here's what we got...[ Go to top ]

    /**
    * @ejb.interface-method
    * @ejb.relation
    * name="UserRole"
    * role-name="UserHasRoles"
    * target-ejb="Role"
    * target-role-name="RoleBelongUsers"
    *
    * @jboss.relation-table
    * table-name="ROLE_FOR_USER"
    *
    * @jboss.target-relation
    * fk-constraint="yes"
    * related-pk-field="id"
    * fk-column="USER_ID"
    * @jboss.relation
    * fk-constraint="yes"
    * related-pk-field="id"
    * fk-column="ROLE_ID"
    */
    public abstract Collection getRoles();

    The ROLE_FOR_USER is a relation table where one field is USER_ID the other is ROLE_ID. This code works with JBoss 3.2.2, 3.2.3