1 Reply Latest reply on Sep 27, 2002 2:10 PM by Dain Sundstrom

    Problem with M:N CMR on Jboss 3.0.2

    Bruce McKernan Newbie

      Hi,

      I am having on going difficulty making a CMR relationship between two EJBs work. I am currently using:

      Mac OS X 10.2
      Jboss 3.0.2
      Sybase ASE-12.5

      I get an error message on deployment of my application.ear file when I copy it into JBOSS_HOME/server/deploy as follows:

      [ServiceController] Problem starting service jboss.j2ee:service=EJB,jndiName=SupplierHome
      org.jboss.deployment.DeploymentException: Both roles of a relation-table mapped relationship must have key fields: ejb-relation-name=Product-Supplier

      following is a description of the EJBs I am trying to use, as well as the Database tables and my ejb-jar.xml , jboss.xml and jbosscmp-jdbc.xml files. Thanks in advance for any help you can provide

      Bruce

      ---------EJBs-----------------

      I have two EJBs Product and Supplier that are in a M:N relationship.

      The Product EJB has amongst other fields productID which acts as its primary key in its mapped database table. I have also included in the Bean definition the following abstract accessor methods to manage its part of the relationship:

      public abstract Collection getSuppliers();
      public abstract void setSuppliers(Collection suppliers);

      Likewise the Supplier EJB has a supplierID and the following relationship abstract methods:

      public abstract Collection getProducts();
      public abstract void setProducts(Collection products);

      I wish to relate them using a relation table mapping and an underlying table in the data base called "catalogue" (see below)

      --------Database------

      table - products contains all the products data including product_id as the primary key.

      table - suppliers contains all the suppliers data including supplier_id as the primary key.

      table - catalogue contains thre columns, namely:
      entry_id as its own primary key and columns product_id and supplier_id to create the M:N relationship.

      ----- configuration files-------------

      ejb-jar.xml
      <ejb-jar>
      <enterprise-beans>

      <ejb-name>Supplier</ejb-name>
      com.county.bloom.shop.SupplierHome
      com.county.bloom.shop.Supplier
      <ejb-class>com.county.bloom.shop.SupplierBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.county.bloom.shop.SupplierPK</prim-key-class>

      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>SupplierBean</abstract-schema-name>

      <cmp-field>
      <field-name>supplierID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>classification</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>postalCode</field-name>
      </cmp-field>


      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[SELECT OBJECT(a) FROM SupplierBean AS a WHERE a.name = ?1]]>
      </ejb-ql>




      <ejb-name>Product</ejb-name>
      com.county.bloom.shop.ProductHome
      com.county.bloom.shop.Product
      <ejb-class>com.county.bloom.shop.ProductBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.county.bloom.shop.ProductPK</prim-key-class>

      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ProductBean</abstract-schema-name>

      <cmp-field>
      <field-name>productID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>weight</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>volume</field-name>
      </cmp-field>


      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[SELECT OBJECT(a) FROM ProductBean AS a WHERE a.name = ?1]]>
      </ejb-ql>



      <ejb-name>Catalogue</ejb-name>
      com.county.bloom.shop.CatalogueHome
      com.county.bloom.shop.Catalogue
      <ejb-class>com.county.bloom.shop.CatalogueBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.county.bloom.shop.CataloguePK</prim-key-class>

      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>CatalogueBean</abstract-schema-name>

      <cmp-field>
      <field-name>entryID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>supplierID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>productID</field-name>
      </cmp-field>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>Product-Supplier</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Product-Has-Suppliers
      </ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Product</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>suppliers</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Supplier-Has-Products
      </ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Supplier</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>products</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      </ejb-jar>


      --------------------------------------------
      jbosscmp-jdbc.xml


      <jbosscmp-jdbc>
      <enterprise-beans>

      <ejb-name>Supplier</ejb-name>
      <table-name>suppliers</table-name>
      <cmp-field>
      <field-name>supplierID</field-name>
      <column-name>supplier_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>classification</field-name>
      <column-name>classification</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      <column-name>city</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>postalCode</field-name>
      <column-name>postal_code</column-name>
      </cmp-field>


      <ejb-name>Product</ejb-name>
      <table-name>products</table-name>
      <cmp-field>
      <field-name>productID</field-name>
      <column-name>product_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>weight</field-name>
      <column-name>weight</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>volume</field-name>
      <column-name>volume</column-name>
      </cmp-field>


      <ejb-name>Catalogue</ejb-name>
      <table-name>catalogue</table-name>
      <cmp-field>
      <field-name>entryID</field-name>
      <column-name>entry_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>supplierID</field-name>
      <column-name>supplier_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>productID</field-name>
      <column-name>product_id</column-name>
      </cmp-field>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>Product-Supplier</ejb-relation-name>
      <relation-table-mapping>
      <table-name>catalogue</table-name>
      </relation-table-mapping>
      <ejb-relationship-role>
      <!-- outdented to fit on a printed page -->
      <ejb-relationship-role-name>Product-Has-Suppliers</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>productID</field-name>
      <column-name>product_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <!-- outdented to fit on a printed page -->
      <ejb-relationship-role-name>Supplier-Has-Products</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>supplierID</field-name>
      <column-name>supplier_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>

      </jbosscmp-jdbc>

      -------------------------------------------------
      jboss.xml



      false

      <enterprise-beans>

      <ejb-name>Supplier</ejb-name>
      <jndi-name>SupplierHome</jndi-name>


      <ejb-name>Product</ejb-name>
      <jndi-name>ProductHome</jndi-name>


      <ejb-name>Catalogue</ejb-name>
      <jndi-name>CatalogueHome</jndi-name>

      </enterprise-beans>

      <resource-managers>
      <resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
      <res-name>SybaseDS</res-name>
      <res-jndi-name>java:/SybaseDS</res-jndi-name>
      </resource-manager>
      </resource-managers>