9 Replies Latest reply on May 17, 2003 10:16 PM by joanwaters

    Error with EJB relationship

    joanwaters Newbie

      Hello,

      I am trying to deploy my test bean with JBoss-3.0.4 and it gives the following error with the relationship.


      [ObjectName: jboss.j2ee:jndiName=Emp,service=EJB
      state: FAILED
      I Depend On:
      Depends On Me: org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields: ejb-relation-name=EMP-DEPT, ObjectName: jboss.j2ee:jndiName=Dept,service=EJB
      state: FAILED
      I Depend On:
      Depends On Me: org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields: ejb-relation-name=EMP-DEPT]


      this is the way i defined the relation

      <!-ejb-jar.xml ->


      <ejb-relation>
      <ejb-relation-name>EMP-DEPT</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>EMP-has-a-DEPT</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Emp</ejb-name>
      </relationship-role-source>
      <cmr-field><cmr-field-name>DEPT_ID</cmr-field-name></cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>DEPT-has-EMP</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Dept</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      <!-jbosscmp-jdbc.xml ->


      <ejb-relation>
      <ejb-relationship-name>EMP-DEPT</ejb-relationship-name>
      <foreign-key-mapping />
      <ejb-relationship-role>
      <ejb-relationship-role-name>EMP-has-a-DEPT</ejb-relationship-role-name>
      <key-fields />
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>DEPT-has-EMP</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>DEPT_ID</field-name>
      <column-name>DEPT_ID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      to check further the source code is attached. every help will be appriciated as am knocking my head for some days on this.

      thanks in advance

      joan

        • 1. Re: Error with EJB relationship
          Juha Lindfors Master

          can't see the source attachment...

          curious about your accessor method naming, since you're using all uppercase DEPT_ID as your CMR field name... this field is case sensitive, so for instance setDepartmentID maps to <field-name>departmentID</field-name> (notice the change in case)

          • 2. Re: Error with EJB relationship
            joanwaters Newbie

            Hi Juha,

            I was't able to attach the files then.

            • 3. Re: Error with EJB relationship
              Juha Lindfors Master

              try switching the key field mapping to the EMP side of the relationship in jbosscmp-jdbc.xml

              • 4. Re: Error with EJB relationship
                joanwaters Newbie

                I have changed as you said but still the problem exists, please see the attachments.

                • 5. Re: Error with EJB relationship
                  Jon Barnett Master

                  The XML looks fine. As a test to see whether the processing/interpretation of the XML is at fault, why don't you try moving the relationship role with key fields to the front - rather than having the relationship role without any key fields first in the sequence of relationship role declarations in jbosscmp-jdbc.xml. At least it will match the guide's example. I'd be surprised if the sequence altered anything but if you've exhausted everything else, it is worth a shot.

                  • 6. Re: Error with EJB relationship
                    torquil Newbie

                    In the attached .zip it looks like the relationship name is inconsistent in the two .xml files ("EMP-DEPT" and "DEPT-EMP").

                    Perhaps there is also a problem with your field names. As one of the other answers pointed out, when you define CMP field accessors "getBlah()" and "setBlah()", you will generate a field (on your EJB) called "blah". The field names in your code may thus be "dEPT_ID" and "eMP_ID", so you may need to change your xml accordingly.

                    Other than that, I can't see any obvious problem with your XML (but I'm certainly no expert).

                    It may be worth trying xdoclet to generate your EJB files, including the deployment descriptors. JBoss supplies an xdoclet template project (which has a few errors), and there is also an XPETSTORE sample application.

                    I have attached xdoclet generated xml for a one-to-many, biderectional relation, such as the one you are defining. In this model, a "ledger" has a collection of "LedgerEntries". The LedgerEntry table has a "LEDGERFK" field, specifying the foreign key of the associated ledger. The ledger EJB has a fild called "key".

                    Hope this helps. Good luck.

                    • 7. Re: Error with EJB relationship
                      joanwaters Newbie


                      Thank you all for the help, Problem with relationships got corrected when I changed the case of the fields. But now I am getting the following error with the EJBQL.
                      This comes with 'WHERE' clause, when the this clause removed it works fine.


                      MBeans waiting for other MBeans:
                      [ObjectName: jboss.j2ee:jndiName=local/Dept,service=EJB
                      state: FAILED
                      I Depend On:
                      Depends On Me: org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "p.emp_id" at line 3, column 25.
                      Was expecting one of:
                      "NOT" ...
                      "(" ...
                      <COLLECTION_VALUED_PATH> ...
                      <STRING_VALUED_PATH> ...
                      "CONCAT" ...
                      "SUBSTRING" ...
                      <BOOLEAN_VALUED_PATH> ...
                      <DATETIME_VALUED_PATH> ...
                      <ENTITY_VALUED_PATH> ...
                      <IDENTIFICATION_VARIABLE> ...
                      <NUMERIC_VALUED_PATH> ...
                      "LENGTH" ...
                      "LOCATE" ...
                      "ABS" ...
                      "SQRT" ...
                      "+" ...
                      "-" ...
                      <INTEGER_LITERAL> ...
                      <FLOATING_POINT_LITERAL> ...
                      <NUMERIC_VALUED_PARAMETER> ...
                      )]


                      This is how the query defined.


                      <query-method>
                      <method-name>findByEmp_id</method-name>
                      <method-params>
                      <method-param>java.lang.Number</method-param>
                      </method-params>
                      </query-method>
                      <ejb-ql><![CDATA[
                      SELECT OBJECT(p)
                      FROM emp p
                      WHERE p.emp_id=?1
                      ]]></ejb-ql>



                      • 8. Re: Error with EJB relationship
                        torquil Newbie

                        Try

                        SELECT OBJECT(p)
                        FROM emp AS p
                        WHERE p.emp_id=?1

                        • 9. Re: Error with EJB relationship
                          joanwaters Newbie

                          This error comes with fields which is having data type java.lang.Number.

                          <method-param>java.lang.Number</method-param>

                          It works fine with String and Date. Is there any problem in using Number !!.