1 Reply Latest reply on Apr 29, 2002 4:10 PM by Dain Sundstrom

    foreign-key mapping is not allowed to have key-fields

    daftarie Newbie

      Hello,

      when deploying CMP entity beans with a foreign-key parent-child relation we get always the same error:

      12:21:24,730 ERROR [EntityContainer] Exception in service lifecyle operation: create
      org.jboss.deployment.DeploymentException: Role: child-has-parent with multiplicity many using foreign-key mapping is not allowed to have key-fields.


      The tables have the type innodb in mysql and are created like following:

      CREATE TABLE `parent` (
      `id` int(3) unsigned NOT NULL default '0',
      PRIMARY KEY (`id`)
      ) TYPE=InnoDB;

      CREATE TABLE `child` (
      `id` int(3) unsigned NOT NULL default '0',
      `parentId` int(3) unsigned NOT NULL default '0',
      PRIMARY KEY (`id`),
      KEY `NewIndex` (`parentId`),
      FOREIGN KEY (parentId) references parent(id)
      ) TYPE=InnoDB;

      Now the deployment descriptors for JBoss 3.0 (they are generated via middlegen):
      --------------ejb-jar.xml-------------------------
      ...
      <!-- Relationships -->

      <ejb-relation>
      <ejb-relation-name>parent-child</ejb-relation-name>
      <!-- bidirectional -->
      <ejb-relationship-role>
      <ejb-relationship-role-name>parent-has-child</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Parent</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>childs</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>child-has-parent</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Child</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>parent</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      ...
      ----------------jboss-cmp-jdbc-----------------------
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

      <jbosscmp-jdbc>

      java:/DefaultDS
      <datasource-mapping>mySQL</datasource-mapping>


      <enterprise-beans>


      <ejb-name>Child</ejb-name>
      <table-name>child</table-name>

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




      <ejb-name>Parent</ejb-name>
      <table-name>parent</table-name>

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



      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>parent-child</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>parent-has-child</ejb-relationship-role-name>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>child-has-parent</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>parentId</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      </jbosscmp-jdbc>

      What's wrong with this? We use JBoss 3.0RC1.

      Gitti