4 Replies Latest reply on Oct 2, 2002 8:08 PM by gong zin

    XDoclet tags for many-to-many relationships

    Stephen Coy Novice

      Are there any xdoclet @jboss:relation attributes for specifying the join table in a many-to-many relationship?

      At the moment, I'm manually adding:

      <relation-table-mapping>
      <table-name>USERS_ROLES</table-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      </relation-table-mapping>

      to jbosscmp-jdbc.xml.

      This is of course for JBoss 3.0.

        • 1. Re: XDoclet tags for many-to-many relationships
          Alexey Loubyansky Master

          It seems like there isn't for now. I do it manually too.

          • 2. Re: XDoclet tags for many-to-many relationships
            Stephen Coy Novice

            It looks like we don't need this if all the jboss relationship tags are set up properly, unless you really want to specify a table name.

            JBoss manages to derive a reasonable table name for itself.

            • 3. Re: XDoclet tags for many-to-many relationships
              Alex Cyn Newbie

              Yes, I just have found how to do this:
              ProductEntityBean CMR field:
              /**
              * @ejb:relation name="name1"
              * role-name="role1" multiple="yes"
              * @jboss:relation-table
              * table-name="product_category"
              * @jboss:relation
              * related-pk-field="id" fk-column="category_id"
              */
              public abstract Collection getCategories();

              CategoryEntityBean CMR field:
              /**
              * @ejb:relation name="name1"
              * role-name="role2" multiple="yes"
              * @jboss:relation-table
              * table-name="product_category"
              * @jboss:relation
              * related-pk-field="id" fk-column="product_id"
              */
              public abstract Collection getProducts();

              • 4. Re: XDoclet tags for many-to-many relationships
                gong zin Newbie

                just thought i could add the unidirectional many to many code: (i am using xdoclet 1.12)
                in the rolebean:
                /**
                * @ejb:interface-method view-type="both"
                */
                public abstract Collection getUsers();
                /**
                * @ejb:interface-method view-type="both"
                */
                public abstract void setUsers(Collection users);

                in the userbean:
                /**
                * @ejb:interface-method view-type="both"
                * @ejb:relation
                * name="User-Roles"
                * role-name="User-has-many-Roles"
                * target-ejb="Role"
                * target-role-name="Role-has-many-Users"
                * target-multiple="yes"
                * @jboss:relation fk-constraint="false" related-pk-field="id" fk-column="ROLE_ID"
                * @jboss:target-relation fk-constraint="false" related-pk-field="id" fk-column="USER_ID"
                */
                public abstract Collection getRoles();
                /**
                * @ejb:interface-method view-type="both"
                */
                public abstract void setRoles(Collection roles);