3 Replies Latest reply on Nov 4, 2003 3:26 AM by jdijkmeijer

    m:n bidirectional woes.

    jdijkmeijer Newbie

      Hi,

      I'm trying to get m:n bidirectional relationships to work, and I'm a bit stuck so far.
      using jboss 3.2.1, I've 2 EJB beans:
      Role and Subject connected linked together by Actor. (Actor does not have an associated entitybean) All the tables are there in the database And querying on them works fine by using the generated EJB's.
      However when I do a call in a SessionBean (after retrieveing the SubjectLocal and RoleLocal) to either SubjectLocal.getRoles() or RoleLocal.getSubjects() nothing returns. And even worse JBoss doesnot generate error messages.
      I've also tried SubjectLocal.setRoles(set) and RoleLocal.setSubjects(set) which again does not generate any error messages nor an extra column in the db-table actor.
      What can I do to switch on debugging, or can anybody have a quick look on what's going wrong with the sources provided below.
      kind regards,
      Jeroen D

      PS I've also posted this msg on sourceforge.

      Role:
      /* CMR */
      /**
      * @ejb.interface-method
      * view-type = "both"
      * @ejb.relation
      * name = "role-subject"
      * role-name = "roleToSubject"
      * @jboss.relation-table
      * table-name="actor"
      * @jboss.relation
      * fk-column = "subjectid"
      * related-pk-field = "subjectId"
      * @jboss.relation-mapping
      * style = "relation-table"
      * @param subjectCollection
      */
      public abstract java.util.Set getSubjects();

      /**
      * @ejb.interface-method
      * view-type="local"
      *
      * @param subjectCollection java.util.Set
      */
      public abstract void setSubjects(java.util.Set subjectCollection);

      SubjectBean:
      /**
      * @ejb.interface-method
      * view-type = "both"
      * @ejb.relation
      * name = "role-subject"
      * role-name = "SubjectToRole"
      * @jboss.relation-table
      * table-name="actor"
      * @jboss.relation
      * fk-column = "roleid"
      * related-pk-field = "roleId"
      * @jboss.relation-mapping
      * style = "relation-table"
      * @param subjectCollection
      */
      public abstract java.util.Set getRoles();

      /**
      * @ejb.interface-method
      * view-type = "both"
      * @param roleCollection
      */
      public abstract void setRoles(java.util.Set roleCollection);

      ejb-jar.xml:

      <ejb-relation >
      <ejb-relation-name>role-subject</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>roleToSubject</ejb-relationship-role-name>
      Many
      <relationship-role-source >
      <ejb-name>Role</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>subjects</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>SubjectToRole</ejb-relationship-role-name>
      Many
      <relationship-role-source >
      <ejb-name>Subject</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>roles</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      </ejb-relation>



      jbosscmp-jdbc.xml:
      <ejb-relation>
      <ejb-relation-name>role-subject</ejb-relation-name>
      <relation-table-mapping>
      <table-name>actor</table-name>
      </relation-table-mapping>

      <ejb-relationship-role>
      <ejb-relationship-role-name>roleToSubject</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>roleId</field-name>
      <column-name>roleid</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>SubjectToRole</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>subjectId</field-name>
      <column-name>subjectid</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>

        • 1. Re: m:n bidirectional woes.
          jdijkmeijer Newbie

          And all of a sudden it was working, made no changes to the code, Hard to say what made it work:
          I inserted a link table bean (actor) and removed an extra fk to another table, so now this table is solely used for m:n relations between subject and role.
          upgrade mysql from 3.0.23 to 4.0.somewhat.
          made changes to clientcode.

          • 2. Re: m:n bidirectional woes.
            Raja Master

            Just in case, you need to see the SQL Statements,
            Turn on the Debug level for org.jboss.ejb.cmp.plugins directory in the log4j.xml on ur conf directory.

            There are some commented samples in the log4j.xml as to how to turn on directory level debugging.

            -Raj

            • 3. Re: m:n bidirectional woes.
              jdijkmeijer Newbie

              Just another steep learning curve:
              lower the teshold in the consoleappender definition of your log4j.xml file. Otherwise you wont see any debug statements.
              At the same time the priority level in the rootcategory should be increased to INFO or higher.