1 Reply Latest reply on Feb 5, 2004 7:36 AM by jhenschel

    Atleast one role of a foreign-key mapped relationship must h

    jhenschel

      Hi all,

      I seem to have a stupid problem modeling a many-to-one relationship between 2 tables:

      one FELD(ID, ...) has many TEST(ID, ..., FELDID, ...)

      I created ejb-jar.xml and jbosscmp-jdbc.xml according to the DTDs and JBoss docs (I'm using JBoss 3.2.2 with Oracle8i).

      Yet, when I deploy the resuzlting ejb.jar file, JBoss throws me the below exception. I'm quite puzzled why this happens, especially since both of my <ejb-relationship-role> elements in jbosscmp-jdbc.xml define a <key-fields> element.

      Below are the relevant snippets from both deployment descriptors, does anyone have a clue why the Exception gets thrown and how to fix it?

      Thanks in advance,
      Joerg Henschel


      Exception thown by JBoss during deployment:
      -----------------------------------------------------------------

      ... <snip/> ...
      16:10:57,094 INFO [EjbModule] Deploying Feld
      16:10:57,104 INFO [EjbModule] Deploying Test
      16:10:57,805 ERROR [EntityContainer] Starting failed
      org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields (or <pri
      mkey-field> is missing from ejb-jar.xml): ejb-relation-name=FELD-TEST
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.<init>(JDBCRelationMetaData.java:347)
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.<init>(JDBCApplicationMetaData.java:412)
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:67)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:676)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.initStoreManager(JDBCStoreManager.java:372)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:320)
       at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:152)
       at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:343)
      ... <snip/> ...

      -----------------------------------------------------------------

      ejb-jar.xml
      -----------------------------------------------------------------
      <relationships>
       <ejb-relation >
       <ejb-relation-name>
       FELD-TEST
       </ejb-relation-name>
       <ejb-relationship-role >
       <ejb-relationship-role-name>
       FELD-has-TESTs
       </ejb-relationship-role-name>
       <multiplicity>
       One
       </multiplicity>
       <relationship-role-source >
       <ejb-name>
       Feld
       </ejb-name>
       </relationship-role-source>
       <cmr-field >
       <cmr-field-name>
       tests
       </cmr-field-name>
       <cmr-field-type>
       java.util.Collection
       </cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>
       TEST-belongsTo-FELD
       </ejb-relationship-role-name>
       <multiplicity>
       Many
       </multiplicity>
       <relationship-role-source>
       <ejb-name>
       Test
       </ejb-name>
       </relationship-role-source>
       <cmr-field >
       <cmr-field-name>
       feld
       </cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
       </relationships>
      


      jbosscmp-jdbc.xml
      ------------------------------------------------------
      <relationships>
       <ejb-relation>
       <ejb-relation-name>
       FELD-TEST
       </ejb-relation-name>
       <foreign-key-mapping/>
       <ejb-relationship-role>
       <ejb-relationship-role-name>
       FELD-has-TESTs
       </ejb-relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>
       id
       </field-name>
       <column-name>
       FELDID
       </column-name>
       </key-field>
       </key-fields>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>
       TEST-belogsTo-FELD
       </ejb-relationship-role-name>
       <key-fields/>
       </ejb-relationship-role>
       </ejb-relation>
       </relationships>
      


        • 1. Re: Atleast one role of a foreign-key mapped relationship mu
          jhenschel

          After a day of debugging I found the cause of the error:

          It seems that JBoss throws this Exception if one or both of the PrimaryKey - classes participating in the relationship has no constructors. Of course PK classes should come with constructors all the time, so I only have myself to blame.

          Still, the error message made me suspect the DD's even they were just fine.