1 Reply Latest reply on Apr 24, 2002 11:07 AM by Dain Sundstrom

    CMR column mapping problem

    Daniele Newbie

      Hi,
      I've encountered a serious limitation regarding CMP2 in JBoss3.0.0beta . I've tried to look at the forums but I've not found anything useful. I hope to have made a mistake!
      My problem is concerned with relationships mapped in an existing database, specifically about foreign keys names.
      To simplify the example suppose we have 2 tables ORDERS (with a primary key column, ID) and LINES (with a pk ID and a foreign key ORDER_ID referencing ORDERS.ID). We want to implement 2 CMP Entity Beans related to those tables, OrderBean and LineBean. Using jbosscmp-jdbc descriptor it's easy to map a cmp-field in its appropriate column in the DataBase, for example:
      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      </cmp-field>
      Now we want to realize a relationship between the beans. In my opinion this is NOT possible!
      In fact defining a relationship in ejb-jar is quite simple. For example:

      <ejb-relation>
      <ejb-relation-name>OrderBean-LineBean</ejb-relation-name>
      <ejb-relationship-role>
      Order
      <ejb-relationship-role-name>OrderRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source>
      OrderBean
      <ejb-name>OrderBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>orderLines</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>LineRelationshipRole</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>LineBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>order</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      With this, OrderBean is provided with a new field called orderLines wich is a Collection of the related LineBeans.
      But whenever an ejbLoad is invoked by the container on a LineBean, an SQL error arises. The issue is that the SQL statement generated by the container is not correct! The SELECT part has a list of all columns of LINES table that we have mapped in the <cmp-field> tags for that Bean (and this is correct) but a new column is added: its name is order. This column is not really defined in the LINES table.
      The problem is that JBoss uses the cmr-field name defined in ejb-jar as the name of the column (the foreign key) in LINES referencing ORDERS table. But this is not a correct behaviour!
      I've tried in many ways to solve the problem, studying jbosscmp-jdbc DTD but there's no way to tell JBoss that the cmr-field order map to the column name ORDER_ID!
      A syntax similar to <cmp-field> would be very useful but is not allowed in the DTD.
      Can someone help me solve this problem? What's wrong in my assertions?

        • 1. Re: CMR column mapping problem
          Dain Sundstrom Master

          > But this is not a correct behaviour!

          This is you opinion. The mapping of a CMP entity is completely up to the container. JBossCMP does allow you to override the mapping in the jbosscmp-jdbc.xml file.

          > I've tried in many ways to solve the problem,
          > studying jbosscmp-jdbc DTD but there's no way to tell
          > JBoss that the cmr-field order map to the
          > column name ORDER_ID!

          Yes there is. Read the dtd again, or read the forum archives.

          > A syntax similar to <cmp-field> would be very useful
          > but is not allowed in the DTD.
          > Can someone help me solve this problem? What's wrong
          > in my assertions?

          It is there you are not looking hard enought. Read the archives of this forum. There have been several examples posted.