EJB CMP/CMR example with JBoss+Xdoclet javacode 9085791

EJB CMP/CMR example with JBoss+Xdoclet

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:

<relationships>
    <ejb-relation>
      <ejb-relation-name>bibliography-may-contain-article</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
          <ejb-relationship-role-name>BibliographyToArticle</ejb-relationship-role-name>
          <key-fields>
             <key-field>
               <field-name>publicationID</field-name>
               <column-name>publication_id_fk</column-name>
             </key-field>
          </key-fields>
</ejb-relationship-role>
      <ejb-relationship-role>
          <ejb-relationship-role-name>ArticleToBibliography</ejb-relationship-role-name>
                  <key-fields/>
</ejb-relationship-role>
    </ejb-relation>
     <!-
       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 <ejb-relation></ejb-relation> markups for those beans.
     ->
</relationships>

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:

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

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

14 Comments

  1. CMR October 26, 2006
  2. Carola December 22, 2005
  3. Jens Wurm November 17, 2005
  4. Breno Leitao February 24, 2005
  5. Arne v.Irmer December 6, 2004
  6. Arne v.Irmer November 30, 2004
  7. Zeger Hendrikse November 23, 2004
  8. Arne v.Irmer November 23, 2004
  9. Arne v.Irmer November 23, 2004
  10. Zeger Hendrikse November 8, 2004
  11. Matt Robinson November 8, 2004
  12. ss October 19, 2004
  13. Janos Czako September 2, 2004
  14. Zeger Hendrikse August 2, 2004