6 Replies Latest reply on Aug 5, 2003 9:18 AM by bartekk

    many-to-many relation with xdoclet

    eddie07

      I am not able to use xdoclet tags to generate the correct jbosscmp-jdbc.xml file for a (bidirectional) m-n-relation.

      This is what I am testing, but jbosscmp-jdbc.xml is not generated (unfortunately without an error message, I am using eclipse).
      part of the code:
      EBUserBean:

      /**
      * @ejb.bean name="EBUser"
      * jndi-name="EBUserTestBean"
      * type="CMP"
      * primkey-field="user_id"
      * schema="UserSchema"
      * cmp-version="2.x"
      *
      * @ejb.persistence
      * table-name="USERS"
      **/
      ...
      public abstract class EBUserBean implements EntityBean {

      ...

      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="UserGroupRelation"
      * role-name="UserhasGroups"
      * target-role-name="GroupsForUser"
      * target-ejb="EBGroup"
      *
      * @jboss.relation-mapping style="relation-table"
      *
      * @jboss.relation-table table-name="USERGROUPRELATION"
      *
      * @jboss.relation related-pk-field = "group_id"
      * fk-column = "USER_ID"
      *
      */

      public abstract java.util.Collection getGroups();
      public abstract void setGroups(java.util.Collection groups);

      EBGroupBean:

      /**
      * @ejb.bean name="EBGroup"
      * jndi-name="EBGroupBean"
      * type="CMP"
      * primkey-field="group_id"
      * schema="GroupSchema"
      * cmp-version="2.x"
      *
      * @ejb.persistence
      * table-name="GROUPS"
      *
      **/
      ...
      public abstract class EBGroupBean implements EntityBean {

      ...

      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="UserGroupRelation"
      * role-name="GroupsForUser"
      * target-role-name="UserhasGroups"
      * target-ejb="EBUser"
      *
      * @jboss.relation-table table-name="USERGROUPRELATION"
      *
      * @jboss.relation related-pk-field = "user_id"
      * fk-column = "GROUP_ID"
      *
      */

      public abstract java.util.Collection getUsers();
      public abstract void setUsers(java.util.Collection users);



      It's working for a unidirectional relation:

      EBUserBean:

      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="UserGroupRelation"
      * role-name="UserhasGroups"
      * target-role-name="GroupsForUser"
      * target-ejb="EBGroup"
      *
      * @jboss.relation-mapping style="relation-table"
      *
      * @jboss.relation-table table-name="USERGROUPRELATION"
      *
      * @jboss.relation related-pk-field = "group_id"
      * fk-column = "USER_ID"
      *
      * @jboss.target-relation related-pk-field = "user_id"
      * fk-column = "GROUP_ID"
      *
      */

      public abstract java.util.Collection getGroups();
      public abstract void setGroups(java.util.Collection groups);


      EBGroupBean:

      /**
      * @ejb.interface-method
      *
      */

      public abstract java.util.Collection getUsers();
      public abstract void setUsers(java.util.Collection users);

      What am I doing wrong here?
      Or can someone show me a working example?

      BTW, the same problem occurs for a 1-n relation, I am only able to use it unidirectional.

      Eddie

        • 1. Re: many-to-many relation with xdoclet
          raja05

          target-* should occur only if the relation is Unidirectional.

          <from_xdoclet>
          target-role-name text Name of the relationship role on the other side of the relation. Should *only* occur if the relation is unidirectional.
          </from_xdoclet>

          Remove the target_role_name and target_ejb ..

          -Raj

          • 2. Re: many-to-many relation with xdoclet
            eddie07

            Thanks for your answer.

            > Remove the target_role_name and target_ejb ..

            I tried this also, but still the xml file is not generated. These are my actual tags:

            EBUserBean:
            /**
            * @ejb.interface-method
            *
            * @ejb.relation
            * name="UserGroupRelation"
            * role-name="UserhasGroups"
            *
            * @jboss.relation-mapping style="relation-table"
            *
            * @jboss.relation-table table-name="EDDIEUSERGROUPRELATION"
            *
            * @jboss.relation related-pk-field = "group_id"
            * fk-column = "USER_ID"
            *
            */

            EBGroupBean:
            /**
            * @ejb.interface-method
            *
            * @ejb.relation
            * name="UserGroupRelation"
            * role-name="GroupsForUser"
            *
            * @jboss.relation-mapping style="relation-table"
            *
            * @jboss.relation-table table-name="EDDIEUSERGROUPRELATION"
            *
            * @jboss.relation related-pk-field = "user_id"
            * fk-column = "GROUP_ID"
            *
            */

            I also tried to use jboss.relation-mapping and jboss.relation-table only in one of the beans.

            Eddie

            • 3. Re: many-to-many relation with xdoclet
              raja05

              Hi Eddie,
              This is from a sample code. The relation isbetween Employees and Projects (m * n)
              /** Employee Bean **/
              /**
              * @ejb.interface-method
              * @ejb.relation name="employee-projects"
              * role-name="employee-belongs-to-projects"
              *
              * @jboss.relation related-pk-field="projectID"
              * fk-column="ProjectID"
              *
              * @jboss.relation-table table-name="T_EMPLOYEE_PROJECTS"
              * create-table="true"
              * remove-table="true"
              */
              public abstract Collection getProjects();


              /** Project Bean **/
              /**
              * @ejb.interface-method
              * @ejb.relation name="employee-projects"
              * role-name="project-has-employees"
              *
              * @jboss.relation related-pk-field="empID"
              * fk-column="EmployeeID"
              *
              * @jboss.relation-table table-name="T_EMPLOYEE_PROJECTS"
              * create-table="true"
              * remove-table="true"
              */
              public abstract Collection getEmployees();

              • 4. Re: many-to-many relation with xdoclet
                eddie07

                > This is from a sample code. The relation isbetween
                > Employees and Projects (m * n)

                Now I am totally confused. I am doing exactly the same (even the order of the tags, blanks, ...) but it doesn't work for me. No idea what the problem could be. :-(
                Nevertheless thanks for your samples. Now I know at least the direction.

                Eddie

                • 5. Re: many-to-many relation with xdoclet
                  raja05

                  i use XDoclet 1.1b2(I think!!)
                  If you want, i can run XDoclet on your classes, can you send me ur beans , just these two beans to
                  raja05 at yahoo dot com

                  Cheers
                  Raj

                  • 6. Re: many-to-many relation with xdoclet
                    bartekk

                    Hi Eddie,
                    I had the same problem. I think it's xdoclet (or Lomboz xdoclet configuration) bug
                    I'm using Eclipse with Lomboz plugin and XDoclet 1.2b3 with JBoss3.2.1.

                    I've found the reason:

                    --- Nested Exception ---
                    xdoclet.XDocletException: The relation FunkcjaInAGrupaFunkcjiRelation seems to be many-to-many (m:n). You should therefore specify weblogic:relation join-table-name="blabla".

                    (I'm using JBoss and I have no idea why should I specyfy weblogic tag - It's a bug I think!)

                    Add xdoclet tag:
                    @weblogic.relation join-table-name="blabla"
                    and it will be working.

                    regards
                    Bart