The generated XML files

Finally, let us inspect the generated jboss.xml, jbosscmp-jdbc.xml and the ejb-jar.xml.

In jboss.xml we find:

      <entity>
         <ejb-name>Bibliography</ejb-name>
         <jndi-name>BibliographyBean</jndi-name>
         <local-jndi-name>BibliographyLocal</local-jndi-name>

      </entity>
      <entity>
         <ejb-name>Article</ejb-name>
         <jndi-name>ArticleBean</jndi-name>
         <local-jndi-name>ArticleLocal</local-jndi-name>

      </entity>

      <session>
         <ejb-name>ArticleFacade</ejb-name>
         <jndi-name>ArticleFacadeBean</jndi-name>
         <local-jndi-name>ArticleFacadeLocal</local-jndi-name>
         <ejb-local-ref>
            <ejb-ref-name>ejb/BibliographyLocal</ejb-ref-name>
            <jndi-name>ejb/BibliographyLocal</jndi-name>
         </ejb-local-ref>

      </session>

We see the artcile facade bean having a reference to the BibliographyBean only. The reference to the article data is now handled by the container!

As already mentioned in this post, I had to change the <ejb-ref> to <ejb-local-ref>.

The section related to the relation mapping in the jbosscmp-jcbc.xml is as follows:

&lt;relationships&gt;
    &lt;ejb-relation&gt;
      &lt;ejb-relation-name&gt;bibliography-may-contain-article&lt;/ejb-relation-name&gt;
&lt;foreign-key-mapping/&gt;
&lt;ejb-relationship-role&gt;
          &lt;ejb-relationship-role-name&gt;BibliographyToArticle&lt;/ejb-relationship-role-name&gt;
          &lt;key-fields&gt;
             &lt;key-field&gt;
               &lt;field-name&gt;publicationID&lt;/field-name&gt;
               &lt;column-name&gt;publication_id_fk&lt;/column-name&gt;
             &lt;/key-field&gt;
          &lt;/key-fields&gt;
&lt;/ejb-relationship-role&gt;
      &lt;ejb-relationship-role&gt;
          &lt;ejb-relationship-role-name&gt;ArticleToBibliography&lt;/ejb-relationship-role-name&gt;
                  &lt;key-fields/&gt;
&lt;/ejb-relationship-role&gt;
    &lt;/ejb-relation&gt;
     &lt;!-
       To add jboss relationships for beans not managed by XDoclet, add
       a file to your XDoclet merge directory called jbosscmp-jdbc-relationships.xml that contains
       the &lt;ejb-relation&gt;&lt;/ejb-relation&gt; markups for those beans.
     -&gt;
&lt;/relationships&gt;

Here we clearly discern the unidirectional character of our mapping, and the correspondence to our Xdoclet tag entries. Note that the “blind side” role name is required: if you leave out this element, or the corresponding target-role-name field of the @ejb.relation tag, the bean does not deploy! Moreover, the <key-fields> section is empty on the “blind side”.

Finally, we’ll have a peek at the ejb-jar.xml. A similar relation mapping section can be found there:

&lt;!- Relationships -&gt;
   &lt;relationships &gt;
      &lt;ejb-relation &gt;
         &lt;ejb-relation-name&gt;bibliography-may-contain-article&lt;/ejb-relation-name&gt;
&lt;ejb-relationship-role &gt;
            &lt;ejb-relationship-role-name&gt;BibliographyToArticle&lt;/ejb-relationship-role-name&gt;
            &lt;multiplicity&gt;One&lt;/multiplicity&gt;
            &lt;cascade-delete/&gt;
            &lt;relationship-role-source &gt;
               &lt;ejb-name&gt;Bibliography&lt;/ejb-name&gt;
            &lt;/relationship-role-source&gt;
            &lt;cmr-field &gt;
               &lt;cmr-field-name&gt;article&lt;/cmr-field-name&gt;
            &lt;/cmr-field&gt;
         &lt;/ejb-relationship-role&gt;
&lt;ejb-relationship-role &gt;
            &lt;ejb-relationship-role-name&gt;ArticleToBibliography&lt;/ejb-relationship-role-name&gt;
            &lt;multiplicity&gt;One&lt;/multiplicity&gt;
            &lt;cascade-delete/&gt;
            &lt;relationship-role-source &gt;
               &lt;ejb-name&gt;Article&lt;/ejb-name&gt;
            &lt;/relationship-role-source&gt;
         &lt;/ejb-relationship-role&gt;
&lt;/ejb-relation&gt;
        &lt;!-
          To add relationships for beans not managed by XDoclet, add
          a file to your XDoclet merge directory called relationships.xml that contains
          the &lt;ejb-relation&gt;&lt;/ejb-relation&gt; markups for those beans.
        -&gt;
   &lt;/relationships&gt;

We see the <relationship> section containing our relationship, with our defined name, containing both the originating side and the “blind side”.