5 Replies Latest reply on Apr 17, 2004 3:36 PM by sesques

    org.jboss.deployment.DeploymentException: No ejb-relationshi

    troypoppe

      I am developing a set of CMP EJBs that have CMRs using XDoclet to generate most of the code required. When I build and deploy this application, I get the following exception for each CMP entity bean that I have developed:

      org.jboss.deployment.DeploymentException: No ejb-relationship-role-name element found

      This is an example of two of my beans, and the resulting ejb-jar.xml and jbosscmp-jdbc.xml files.

      
      package gov.doe.eia.party;
      
      import gov.doe.eia.party.interfaces.PartyLocal;
      import gov.doe.eia.party.interfaces.PartyLocalHome;
      import gov.doe.eia.party.util.PartyUtil;
      import gov.doe.eia.party.vo.PartyValue;
      import gov.doe.eia.party.vo.PersonValue;
      
      import java.util.Collection;
      
      import javax.ejb.CreateException;
      import javax.ejb.EntityBean;
      import javax.ejb.FinderException;
      import javax.naming.NamingException;
      
      /**
       * @ejb.bean name="Person"
       * jndi-name="ejb/Person"
       * local-jndi-name="ejb/PersonLocal"
       * type="CMP"
       * primkey-field="personID"
       * cmp-version="2.x"
       * view-type = "local"
       *
       * @ejb.persistence
       * table-name = "person"
       *
       * @jboss.persistence
       * datasource = "java:/jdbc/PartyDS"
       * datasource-mapping = "Oracle9i"
       * create-table = "false"
       * remove-table = "false"
       *
       * @ejb.value-object
       * name = "Person"
       * match = "*"
       *
       * @ejb.ejb-ref
       * ejb-name = "Party"
       * ref-name = "ejb/PartyLocal"
       * view-type = "local"
       */
      public abstract class PersonBean implements EntityBean
      {
      
       /**
       * Returns the personID
       * @return the personID
       *
       * @ejb.persistent-field
       * @ejb.persistence
       * column-name="personid"
       * sql-type="NUMBER"
       * @ejb.pk-field
       * @ejb.interface-method
       * view-type = "local"
       *
       */
       public abstract java.lang.Integer getPersonID();
      
       /**
       * Sets the personID
       *
       * @param java.lang.Integer the new personID value
       *
       * @ejb.interface-method
       * view-type = "local"
       */
       public abstract void setPersonID(java.lang.Integer personID);
      
       /**
       *
       * @ejb.interface-method
       * view-type = "local"
       *
       * @return
       */
       public abstract PersonValue getPersonValue();
      
       /**
       * @ejb.interface-method
       * view-type = "local"
       *
       * @param valueHolder
       */
       public abstract void setPersonValue(PersonValue valueHolder);
      
       // -------------------------- RELATIONS ---------------------------------//
      
       /**
       * @ejb.relation
       * name = "RoleInstancePerson"
       * role-name = "PersonHasRoleInstances"
       *
       * @ejb.interface-method
       * view-type = "local"
       *
       * @ejb.value-object
       * compose="gov.doe.eia.party.vo.RoleInstanceValue"
       * compose-name="RoleInstance"
       * members="gov.doe.eia.party.interfaces.RoleInstanceLocal"
       * member-name="RoleInstance"
       * relation="external"
       * type="Collection"
       *
       * @jboss.relation
       * fk-column = "personID"
       * related-pk-field = "assignedPerson"
       *
       * @author TPO
       */
       public abstract Collection getRoleInstances();
      
       /**
       * @ejb.interface-method
       * view-type = "local"
       *
       * @jboss.relation
       * fk-column = "personID"
       * related-pk-field = "assignedPerson"
       *
       * @author TPO
       */
       public abstract void setRoleInstances(Collection roleInstances);
      
       /**
       * @ejb.relation
       * name = "PersonParty"
       * role-name = "PersonIsAParty"
       * target-ejb = "Party"
       *
       * @ejb.interface-method
       * view-type = "local"
       *
       * @jboss.relation
       * fk-column = "personID"
       * related-pk-field = "partyID"
       *
       * @ejb.value-object
       * relation = "external"
       *
       * @author TPO
       */
       public abstract PartyLocal getParty();
      
       /**
       * @ejb.interface-method
       * view-type = "local"
       *
       * @jboss.relation
       * fk-column = "personID"
       * related-pk-field = "partyID"
       *
       * @author TPO
       */
       public abstract void setParty(PartyLocal party);
      
       // -------------------------- CREATES ---------------------------------//
      
       /**
       * The ejbCreate method.
       *
       * @ejb.create-method
       */
       public java.lang.Integer ejbCreate(PersonValue personValue)
       throws javax.ejb.CreateException
       {
       // EJB 2.0 spec says return null for CMP ejbCreate methods.
       PartyValue partyValue = new PartyValue(null, new Integer(PartyType.PERSON));
       try
       {
       PartyLocalHome plHome = PartyUtil.getLocalHome();
       PartyLocal pl = plHome.create(partyValue);
       partyValue = pl.getPartyValue();
      
       personValue.setPersonID(partyValue.getPartyID());
       setPersonValue(personValue);
       }
       catch ( NamingException ex )
       {
       }
       catch ( CreateException ex )
       {
       }
      
       return null;
       }
      
       /**
       * The container invokes this method immediately after it calls ejbCreate.
       *
       */
       public void ejbPostCreate(PersonValue personValue)
       throws javax.ejb.CreateException
       {
       try
       {
       PartyLocalHome plHome = PartyUtil.getLocalHome();
       PartyLocal pl = plHome.findByPrimaryKey(getPersonID());
      
       setParty(pl);
       }
       catch ( NamingException ex )
       {
       }
       catch ( FinderException ex )
       {
       }
       }
      }
      


      package gov.doe.eia.party;
      
      import gov.doe.eia.party.vo.PartyValue;
      
      import javax.ejb.EntityBean;
      
      /**
       * @ejb.bean
       * name="Party"
       * jndi-name="ejb/Party"
       * local-jndi-name = "ejb/PartyLocal"
       * type="CMP"
       * primkey-field="partyID"
       * cmp-version="2.x"
       * view-type = "local"
       *
       * @ejb.persistence
       * table-name = "party"
       *
       * @jboss.persistence
       * datasource = "java:/jdbc/PartyDS"
       * datasource-mapping = "Oracle9i"
       * create-table = "false"
       * remove-table = "false"
       *
       * @ejb.value-object
       * name = "Party"
       * match = "*"
       *
       * @ejb.ejb-ref
       * ejb-name = "SequenceManager"
       * ref-name = "ejb/SequenceManagerLocal"
       * view-type = "local"
       */
      public abstract class PartyBean implements EntityBean
      {
      
       /**
       * Returns the partyID
       * @return the partyID
       *
       * @ejb.persistent-field
       * @ejb.persistence
       * column-name="partyID"
       * sql-type="NUMBER"
       * @ejb.pk-field
       * @ejb.interface-method
       *
       */
       public abstract java.lang.Integer getPartyID();
      
       /**
       * Sets the partyID
       *
       * @param java.lang.Integer the new partyID value
       *
       * @ejb.interface-method
       */
       public abstract void setPartyID(java.lang.Integer partyID);
      
       /**
       * Returns the partyTypeID
       * @return the partyTypeID
       *
       * @ejb.persistent-field
       * @ejb.persistence
       * column-name="partyTypeID"
       * sql-type="NUMBER"
       *
       * @ejb.interface-method
       *
       */
       public abstract java.lang.Integer getPartyTypeID();
      
       /**
       * Sets the partyTypeID
       *
       * @param java.lang.Integer the new partyTypeID value
       *
       * @ejb.interface-method
       */
       public abstract void setPartyTypeID(java.lang.Integer partyTypeID);
      
       /**
       *
       * @ejb.interface-method
       * view-type = "local"
       *
       * @return
       */
       public abstract PartyValue getPartyValue();
      
       /**
       * @ejb.interface-method
       * view-type = "local"
       *
       * @param valueHolder
       */
       public abstract void setPartyValue(PartyValue valueHolder);
      
       // -------------------------- RELATIONS ---------------------------------//
      
       // -------------------------- CREATES ---------------------------------//
      
       /**
       * The ejbCreate method.
       *
       * @ejb.create-method
       */
       public java.lang.Integer ejbCreate(PartyValue partyValue)
       throws javax.ejb.CreateException
       {
       // EJB 2.0 spec says return null for CMP ejbCreate methods.
       // TODO: set PK!!
       setPartyValue(partyValue);
       return null;
       }
      
       /**
       * The container invokes this method immediately after it calls ejbCreate.
       *
       */
       public void ejbPostCreate(PartyValue partyValue)
       throws javax.ejb.CreateException
       {
       }
      
      }
      



      <entity >
      <description><![CDATA[]]></description>

      <ejb-name>Party</ejb-name>

      <local-home>gov.doe.eia.party.interfaces.PartyLocalHome</local-home>
      <local>gov.doe.eia.party.interfaces.PartyLocal</local>

      <ejb-class>gov.doe.eia.party.cmp.PartyCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      <reentrant>False</reentrant>
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Party</abstract-schema-name>
      <cmp-field >
      <description><![CDATA[Returns the partyID]]></description>
      <field-name>partyID</field-name>
      </cmp-field>
      <cmp-field >
      <description><![CDATA[Returns the partyTypeID]]></description>
      <field-name>partyTypeID</field-name>
      </cmp-field>
      <primkey-field>partyID</primkey-field>

      <ejb-local-ref >
      <ejb-ref-name>ejb/SequenceManagerLocal</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <local-home>gov.doe.eia.party.interfaces.SequenceManagerLocalHome</local-home>
      <local>gov.doe.eia.party.interfaces.SequenceManagerLocal</local>
      <ejb-link>SequenceManager</ejb-link>
      </ejb-local-ref>

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

      <entity >
      <description><![CDATA[]]></description>

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

      <local-home>gov.doe.eia.party.interfaces.PersonLocalHome</local-home>
      <local>gov.doe.eia.party.interfaces.PersonLocal</local>

      <ejb-class>gov.doe.eia.party.cmp.PersonCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      <reentrant>False</reentrant>
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Person</abstract-schema-name>
      <cmp-field >
      <description><![CDATA[Returns the personID]]></description>
      <field-name>personID</field-name>
      </cmp-field>
      <cmp-field >
      <description><![CDATA[Returns the lastName]]></description>
      <field-name>lastName</field-name>
      </cmp-field>
      <cmp-field >
      <description><![CDATA[Returns the firstName]]></description>
      <field-name>firstName</field-name>
      </cmp-field>
      <primkey-field>personID</primkey-field>

      <ejb-local-ref >
      <ejb-ref-name>ejb/PartyLocal</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>gov.doe.eia.party.interfaces.PartyLocalHome</local-home>
      <local>gov.doe.eia.party.interfaces.PartyLocal</local>
      <ejb-link>Party</ejb-link>
      </ejb-local-ref>

      <!-- Write a file named ejb-finders-PersonBean.xml if you want to define extra finders. -->
      </entity>
      <ejb-relation >
      <ejb-relation-name>PersonParty</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>PersonIsAParty</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source >
      <ejb-name>Person</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>party</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <multiplicity>One</multiplicity>
      <relationship-role-source >
      <ejb-name>Party</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      </ejb-relation>



      <entity>
      <ejb-name>Party</ejb-name>
      <datasource>java:/jdbc/PartyDS</datasource>
      <datasource-mapping>Oracle9i</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <table-name>party</table-name>

      <cmp-field>
      <field-name>partyID</field-name>
      <column-name>partyID</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>partyTypeID</field-name>
      <column-name>partyTypeID</column-name>

      </cmp-field>

      <!-- jboss 3.2 features -->
      <!-- optimistic locking does not express the exclusions needed -->
      </entity>

      <entity>
      <ejb-name>Person</ejb-name>
      <datasource>java:/jdbc/PartyDS</datasource>
      <datasource-mapping>Oracle9i</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <table-name>person</table-name>

      <cmp-field>
      <field-name>personID</field-name>
      <column-name>personid</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>lastName</field-name>
      <column-name>lastName</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>firstName</field-name>
      <column-name>firstName</column-name>

      </cmp-field>

      <!-- jboss 3.2 features -->
      <!-- optimistic locking does not express the exclusions needed -->
      </entity>

      <ejb-relation>
      <ejb-relation-name>PersonParty</ejb-relation-name>

      <ejb-relationship-role>
      <ejb-relationship-role-name>PersonIsAParty</ejb-relationship-role-name>
      <key-fields/>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name></ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>partyID</field-name>
      <column-name>personID</column-name>
      </key-field>
      </key-fields>

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


      Can anyone help me, I cant see find anything wrong with this. I certainly dont understand why I am getting that error.

      Thanks.

      Troy Poppe

        • 1. Re: org.jboss.deployment.DeploymentException: No ejb-relatio
          sesques

          You must declare the relationship on both sides:
          Your forgot the declaration in your Party bean, something like :

           /**
           * @ejb.relation
           * name = "PersonParty"
           * role-name = "PartyHavePerson"
           * target-ejb = "Person"
          




          • 2. Re: org.jboss.deployment.DeploymentException: No ejb-relatio
            troypoppe

             

            "sesques" wrote:
            You must declare the relationship on both sides:
            Your forgot the declaration in your Party bean, something like :

             /**
             * @ejb.relation
             * name = "PersonParty"
             * role-name = "PartyHavePerson"
             * target-ejb = "Person"
            




            Thanks for the reply. I thought it was possible for a CMP bean to have a uni-directional relationship to another CMP bean? (Although the documentation for how to do this in XDoclet is not very good.)

            Ideally, I'd like to not have a method in PartyBean that exposes the relationship to Person. Does that imply that I should put the @ejb.relation in on an abstract method, but not provide an @ejb.interface-method tag?

            Thanks.

            Troy

            • 3. Re: org.jboss.deployment.DeploymentException: No ejb-relatio
              sesques

              Hi,

              What you want to do is possible and correct regarding the ejb spec. But XDoclet is bugged and do not allow a relationship declaration without the associated methods.
              When you do that, XDoclet forget to put a <ejb-relationship-role-name> tag in ejb-jar.xml, and in jbosscmp-jdbc.xml, the tag exists but is empty.

              So, you have 2 solutions:
              1) Declare an abstract method in your Partybean to get Persons (with @ejb.interface-method).
              2) Modify manually ejb-jar.xml and jbosscmp-jdbc.xml after Xdoclet to declare properly the <ejb-relationship-role-name> tag.

              Pascal

              • 4. Re: org.jboss.deployment.DeploymentException: No ejb-relatio
                triathlon98

                No this is not a Xdoclet problem. You have to define the "other-side". See the xdoclet docs for the correct names.

                I had this working, but don't have an example handy.

                Joachim

                • 5. Re: org.jboss.deployment.DeploymentException: No ejb-relatio
                  sesques

                  You right triathlon98, the field is target-role-name in @ejb.relation
                  Thanks