1 Reply Latest reply on Jun 21, 2004 11:29 AM by Christopher Bird

    A CMR Question

    Christopher Bird Newbie

      --- I notice in preview that some key components of the XML get preprocessed and the tags get lost. I am annotaing those lines below......

      I am running JBOSS 3.2.4, Eclipse 2.1.3/Lomboz 2.1.3 with mySQL version 4.0.20b.

      After some much needed help from this forum, I was able to get mysql to act as the relational database for my CMP managed tables. The next tricj is to get CMR working. That has also been frustrating.

      During deployment/startup, I get the following messages from jboss:

      -----------------------------------------------------------------------------------
      MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM:
      ObjectName: jboss.j2ee:jndiName=GroupBean,service=EJB
      state: FAILED
      I Depend On:
      Depends On Me: MBeanException: org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields (or <primkey-field> is missing from ejb-jar.xml): ejb-relation-name=mbrship
      Cause: org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields (or <primkey-field> is missing from ejb-jar.xml): ejb-relation-name=mbrship

      ----------------------------------------------------------------------------------

      The reason that this is a bit strange to me is that the relationship called mbrship does not involve the GroupBean at all. It is currently a 1:m association between PersonBean and MembershipBean.


      I also get a similar message for the PersonBean. That one is at least plausible, since the mbrship association does invoilve Person.

      The ejb-jar.xml CMR snippet looks like this:

      ------------------------------------------------------------------------------------

      <!-- Relationships -->

      <ejb-relation >
      <ejb-relation-name>mbrship</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>is-for</ejb-relationship-role-name>
      Many - multiplicity tag gets lost in display
      <relationship-role-source >
      <ejb-name>Membership</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>person</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>Has</ejb-relationship-role-name>
      One - multiplicity tag gets lost in display
      <relationship-role-source >
      <ejb-name>Person</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>memberships</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      </ejb-relation>


      -----------------------------------------------------------------------------------


      My intent was to define the 1 Person has many Assignments association. That is currently the only CMR that I am dealing with, since I am trying to get it working before building out the full app.

      More of the ejb-jar.xml follows (showing primary key fields).

      -----------------------------------------------------------------------------------


      <![CDATA[]]>

      <ejb-name>Person</ejb-name>

      com.kipoko.main.PersonHome
      com.kipoko.main.Person
      <local-home>com.kipoko.main.PersonLocalHome</local-home>
      com.kipoko.main.PersonLocal

      <ejb-class>com.kipoko.main.PersonCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False - reentrant tag gets lost in display
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Person</abstract-schema-name>
      <cmp-field >
      <![CDATA[Returns the personId]]>
      <field-name>personId</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Returns the personName]]>
      <field-name>personName</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Returns the personJoined]]>
      <field-name>personJoined</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Returns the personLeft]]>
      <field-name>personLeft</field-name>
      </cmp-field>
      <primkey-field>personId</primkey-field>


      <query-method>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(a) FROM Person as a]]></ejb-ql>

      <!-- Write a file named ejb-finders-PersonBean.xml if you want to define extra finders. -->



      <![CDATA[]]>

      <ejb-name>Group</ejb-name>

      com.kipoko.main.GroupHome
      com.kipoko.main.Group
      <local-home>com.kipoko.main.GroupLocalHome</local-home>
      com.kipoko.main.GroupLocal

      <ejb-class>com.kipoko.main.GroupCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False - reentrant tag gets lost in display
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>group</abstract-schema-name>
      <cmp-field >
      <![CDATA[Returns the groupId]]>
      <field-name>groupId</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Returns the groupName]]>
      <field-name>groupName</field-name>
      </cmp-field>
      <primkey-field>groupId</primkey-field>


      <query-method>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(a) FROM group as a]]></ejb-ql>

      <!-- Write a file named ejb-finders-GroupBean.xml if you want to define extra finders. -->



      <![CDATA[]]>

      <ejb-name>Membership</ejb-name>

      com.kipoko.main.MembershipHome
      com.kipoko.main.Membership
      <local-home>com.kipoko.main.MembershipLocalHome</local-home>
      com.kipoko.main.MembershipLocal

      <ejb-class>com.kipoko.main.MembershipCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False - reentrant tag gets lost in display
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>membership</abstract-schema-name>
      <cmp-field >
      <![CDATA[Returns the membershipID]]>
      <field-name>membershipID</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Returns the membershipPersonLeft]]>
      <field-name>membershipPersonLeft</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Returns the membershipPersonJoined]]>
      <field-name>membershipPersonJoined</field-name>
      </cmp-field>
      <primkey-field>membershipID</primkey-field>


      <query-method>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(a) FROM membership as a]]></ejb-ql>

      <!-- Write a file named ejb-finders-MembershipBean.xml if you want to define extra finders. -->


      The Bean code (before LOMBOZ generation) looks like this for MemberShipBean...

      -----------------------------------------------------------------------------
      /**
      * @ejb.bean name="Membership"
      * jndi-name="MembershipBean"
      * type="CMP"
      * primkey-field="membershipID"
      * schema="membership"
      * cmp-version="2.x"
      *
      *
      *
      * @ejb.persistence
      * table-name="MEMBERSHIP"
      *
      * @ejb.finder
      * query="SELECT OBJECT(a) FROM membership as a"
      * signature="java.util.Collection findAll()"
      *
      *
      *
      **/

      public abstract class MembershipBean implements EntityBean {

      EntityContext ctx;

      /**
      * The ejbCreate method.
      *
      * @ejb.create-method
      */
      public java.lang.String ejbCreate(
      String membershipStart,
      String membershipEnd,
      String personId)
      throws javax.ejb.CreateException {

      String membershipId = "M" + PKGenerator.NewKey(1000001);
      this.setMembershipID(membershipId);
      this.setMembershipPersonJoined(membershipStart);
      this.setMembershipPersonLeft(membershipEnd);

      return null;
      }

      /**
      * The container invokes this method immediately after it calls ejbCreate.
      *
      */
      public void ejbPostCreate(
      String membershipStart,
      String membershipEnd,
      String personId)
      throws javax.ejb.CreateException {
      try {
      InitialContext ctx = new InitialContext();
      PersonHome aPersonHome = (PersonHome) ctx.lookup("java:comp/env/ejb/PersonHome");
      Person aPerson = aPersonHome.findByPrimaryKey(personId);
      setPerson(aPerson);
      }
      catch (Exception e) {
      System.out.println("Can't find Person");
      }
      }
      --------------------------------------------------------------------------------
      The error handling is clearly not fully developed!

      I do not have any methods on the Person side of the relationship for inserting assignments. I also don't (yet) have any methods for accessing assignments for person. The accessors will be written once I have been able to get basic deployment and creation to work.

      I have successfully been able to use just CMP fields, so I know I can connect to the database correctly.

      I apologize (again) for the length of this post. I just wanted any interested parties to have all the data I could dig up.

      Thanks in advance for replies.

      PS. I am laying down the $ for the doc set from JBOSS riight now!!!!

      C

        • 1. Re: A CMR Question - Never Mind! Needed to edit jbosscmp-jdb
          Christopher Bird Newbie

          After reading the doc and looking at my jbosscmp-jdbc.xml file, I realized that I needed to edit the relationships section. I had hoped that LOMBOZ would have done that bit, but no such luck (or more likely a DFU error on my part). So by inserting the following Lines denoted with -------> and lines in between), deployment magically happened! Whether the logic works or not is a different issue!

          ----------------------------------------------------------------------------------


          <ejb-relation>
          <ejb-relation-name>mbrship</ejb-relation-name>

          <foreign-key-mapping/>

          <ejb-relationship-role>
          <ejb-relationship-role-name>is-for</ejb-relationship-role-name>
          <key-fields/>



          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>Has</ejb-relationship-role-name>
          ---------> <key-fields>
          <key-field>
          <field-name>personId</field-name>
          <column-name>memberPersonId</column-name>
          </key-field>
          ----------> </key-fields>
          </ejb-relationship-role>
          </ejb-relation>



          ----------------------------------------------------------------------

          Thanks to all who demonstrated enough patience to get this far!

          C