2 Replies Latest reply on Jan 10, 2002 11:29 AM by giunti

    CMP 2 Relations and JBoss

    giunti

      Hi,

      I am trying to implement a simple One to Many relation using Jboss 3.0 Alpha and a tool named EjbGen (http://www.beust.com/cedric/ejbgen/) which speeds up EJB creation and maintanance.
      I can create the correct sources (Beans, Local interfaces, ejb-jar.xml), compile and delpoy, but when I try to use the relation I get an exception like the following:

      Column not found: UTENTEEJB_ACCESSI_NAME in statement [SELECT numero FROM AccessoEJB WHERE UtenteEJB_accessi_name='giunti']; nested exception is:
      javax.ejb.EJBException: FindByForeignKey failed

      I am not a CMP 2.0 guru, but it seems that JBoss assume the existence of a the field UtenteEJB_accessi_home in the table Accessi, but it does not really create it (both Accesso and Utente are CMP 2.0 Entity Beans).

      Here follows a snippet from the ejb-jar.xml which seems correct to me:


      <ejb-relation>
      <ejb-relation-name>Utente-Accesso</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Accessi-di-un-Utente</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>AccessoEJB</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Utente-ha-Accessi</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>UtenteEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>accessi</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>



      I can post sources too if you need.
      Can anybody help me?
      Thanks in advance.

        • 1. Re: CMP 2 Relations and JBoss
          brianhuang2002

          Have you checked if the foreign key field exists in your table? Did you include a foeiegn key mapping on the file jbosscmp-jdbc.xml?

          You can find answers about CMP 2.0 from the US$5.00 document.

          • 2. Re: CMP 2 Relations and JBoss
            giunti

            I found the problem: JBoss had not altered the table adding the foreign key field.
            Undeploying the EJBs, deleteing tables and deploying again it worked!

            Maybe that JBoss 3.0 Alpha does not alter tables to add relation foreign keys?

            PS: I purchased the CMP manual (for US$10.00), it is interesting but it not solved my problem. Anyway I am proud to contribute!