1 Reply Latest reply on May 13, 2002 7:45 PM by dsundstrom

    Table mapping relationship is not creating right attribute n

    fastball

      Hi people!

      I have two tables that must be mapped as a many to many relationship. Thus, we need a relation table that contains both table's Pks as foreign keys. My sample structure is similar to:

      Table01
      ---------------------------------------------
      idTable01..varchar(2)...not null..pk
      name.......varchar(10)


      Table02
      -------------------------------------
      idTable02..varchar(2)...not null..pk
      name.......varchar(10)

      relation mapping in ejb-jar.xml as follows:


      <ejb-relation>
      <ejb-relation-name>Table01_Table02</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Table01-has-Table02</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Table01JAR</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>tables02</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Table02-has-Table01</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Table02JAR</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>tables01</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      ________________________________________________________
      And relation mapping in jbosscmp-jdbc.xml looks like:


      <ejb-relation>
      <ejb-relation-name>Table01_Table02</ejb-relation-name>
      <relation-mapping-style>relation-table</relation-mapping-style>
      <preferred-relation-mapping>relation-table</preferred-relation-mapping>
      <relation-table-mapping>
      <table-name>RelationT1T2</table-name>
      <create-table>true</create-table>
      <remove-table>false</remove-table>
      <pk-constraint>true</pk-constraint>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>idTable01</field-name>
      <column-name>idTable01_fk</column-name>
      </key-field>
      </key-fields>
      <key-fields>
      <key-field>
      <field-name>idTable02</field-name>
      <column-name>idTable02_fk</column-name>
      </key-field>
      </key-fields>
      </relation-table-mapping>
      </ejb-relation>


      ----------------------------------------------------------
      Table01 and Table02 are created as described in the XML, but the relation table is not. The name of R.T. is ok, but the fields is not the same as declared.
      The metadata of created relation table its seems to:

      CREATE TABLE RelationT1T2
      (
      Table01JAR VARCHAR(12) NOT NULL,
      Table02JAR VARCHAR(12) NOT NULL,
      (...)

      Note that the name of relation fields are the same name of the relation beans, and not what I informed in jbosscmp-jdbc.xml.

      The database schema must be:
      CREATE TABLE RelationT1T2
      (
      idTable01_fk VARCHAR(12) NOT NULL,
      idTable02_fk VARCHAR(12) NOT NULL,
      (...)

      Is there something wrong?
      I think JBoss is ignoring my attribute mappings...

      Thank U.