1 Reply Latest reply on Nov 24, 2004 3:28 PM by jobor

    CMR and SQL create

    kongdy

      Hi,

      I have a problem regarding CMR. As for example, I have two tables ?Test? and ?TestParams?. The tables definitions are as follows:

      Test
      test_id varchar(20) not null? primary key
      test_name varchar(20) not null

      Test_Params
      test_id varchar(20) not null ? primary key (references to testID in Test)
      examiner varchar(20) not null ? primary key
      length int not null


      I am trying to establish a 1:N relationship between them. I have the relevant getters and setters in the two entity beans.

      Getters/Setters in Test:
      public abstract Collection getTestParamLists();
      public abstract void setTestParamLists(Collection testParamLists);

      Getters/Setters in TestParams:
      public abstract TestLocal getTest();
      public abstract void setTest(TestLocal test);

      Below are the extracts from the ejb-jar and jbosscmp-jdbc:

      Ejb-jar:


      <ejb-relation>
      <ejb-relation-name>Test-TestParams</ejb-relation-name>
      <ejb-relationship-role>
      Test
      <ejb-relationship-role-name>Test-has-Params</ejb-relationship-role-name>
      One
      <relationship-role-source>
      test
      <ejb-name>Test</ejb-name>
      </relationship-role-source>
      <cmr-field>
      paramLists
      <cmr-field-name>paramLists</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      Test
      <ejb-relationship-role-name>Params-belong-to-Test</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      testParams
      <ejb-name>Test_Params</ejb-name>
      </relationship-role-source>
      <cmr-field>
      test
      <cmr-field-name>test</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>



      jbosscmp-jdbc:


      <ejb-relation>
      <ejb-relation-name>Test-TestParams</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Test-has-Params</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>testId</field-name>
      <column-name>test_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Params-belong-to-Test</ejb-relationship-role-name>
      </ejb-relationship-role>
      </ejb-relation>


      I tried to create a Test bean and a TestParams bean by issuing the following codes:
      TestLocal newTest=testLocalHome.create(testobject);
      testParamsLocalHome.create(paramObject, newTest);

      The Test bean is successfully created, but not the TestParams bean.
      I got the following error:

      javax.ejb.CreateException: javax.ejb.CreateException: Could not create entity:java.sql.SQLException: Unknown column 'test' in 'field list'

      I looked at the log file: it is trying to execute an insert SQL statement

      Executing SQL: INSERT INTO TEST_PARAMS (test_ID, examiner, length, test) VALUES (?, ?, ?, ?)

      It seems like Jboss thinks that my cmr field is a cmp field? What do I need to change?

      Any help is appreciate.

      Thanks

        • 1. Re: CMR and SQL create
          jobor

          I don't know how you did get it to work but I think the 2 descriptor parts should be as followed.

          <ejb-relation>
           <ejb-relation-name>Test-TestParams</ejb-relation-name>
           <ejb-relationship-role>
           <ejb-relationship-role-name>Test-has-Params</ejb-relationship-role-name>
           <multiplicity>One</multiplicity>
           <relationship-role-source>
           <ejb-name>Test</ejb-name>
           </relationship-role-source>
           <cmr-field>
           <cmr-field-name>paramLists</cmr-field-name>
           <cmr-field-type>java.util.Collection</cmr-field-type>
           </cmr-field>
           </ejb-relationship-role>
           <ejb-relationship-role>
           <ejb-relationship-role-name>Params-belong-to-Test</ejb-relationship-role-name>
           <multiplicity>Many</multiplicity>
           <relationship-role-source>
           <ejb-name>Test_Params</ejb-name>
           </relationship-role-source>
           </ejb-relationship-role>
          </ejb-relation>
          
          <ejb-relation>
           <ejb-relation-name>Test-TestParams</ejb-relation-name>
           <ejb-relationship-role>
           <ejb-relationship-role-name>Test-has-Params</ejb-relationship-role-name>
           <key-fields>
           <key-field>
           <field-name>testId</field-name>
           <column-name>test_id</column-name>
           </key-field>
           </key-fields>
           </ejb-relationship-role>
           <ejb-relationship-role>
           <ejb-relationship-role-name>Params-belong-to-Test</ejb-relationship-role-name>
           </ejb-relationship-role>
          </ejb-relation>
          


          Johan