6 Replies Latest reply on Jun 15, 2005 8:38 AM by rpa_rio

    CMR question

    tinnes

      I have three tables:

      Doctor - PK is Id
      DoctorSpecialty - PK is DoctorId, SpecialtyId
      Specialty PK is Id

      Doctor has many DoctorSpecialty. DoctorSpecialty has 1 Specialty. Basically, in relational speak, DoctorSpecialty resolves a many to many relationship between Doctor and Specialty

      I have defined a CMR 1 to many unidirectional relationship between Doctor and DoctorSpecialty. Fine.

      I have also defined a CMR 1 to 1 unidirectional relationship between DoctorSpecialty and Specialty (Specialty contains the description I need in my application). When I deploy to JBoss 3.0.1, I get the following exception:

      2002-07-15 10:13:05,656 WARN [org.jboss.system.ServiceController] Problem starting service jboss.j2ee:service=EJB,jndiName=TDoctorSpecialty
      org.jboss.deployment.DeploymentException: Mappings were not provided for all fields: unmaped fields=[doctorId]
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.loadKeyFields(JDBCRelationshipRoleMetaData.java:390)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.init(JDBCRelationshipRoleMetaData.java:157)

      My jbosscmp-jdbc.xml has the following entry for the relation in question:

      <ejb-relation>
      <ejb-relation-name>tDoctorSpecialty-tSpecialty</ejb-relation-name>
      <foreign-key-mapping></foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>TDoctorSpecialtyRelationshipRole</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>specialtyId</field-name>
      <column-name>id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>TSpecialtyRelationshipRole</ejb-relationship-role-name>
      </ejb-relationship-role>
      </ejb-relation>


      Any help would be appreciated.


      Tom

        • 1. Re: CMR question
          dsundstrom

          It looks like you have the key-fields in the wrong role.

          • 2. Re: CMR question
            tinnes

            Thanks Dain,

            I am using JBuilder 6 with the JBuilder Open Tool. If the XML is in-deed incorrect then the OpenTool is generating it incorrectly. I have tried manually moving things to different roles and it still doesn't work. Is there examples of 1 to many and 1 to 1 mappings that I can look at to see how to correctly configure my XML. Is there another tool like XDoclet that people use to generate the XML for them? If so are there examples of how to configure it to use with these types of relationships?

            Tom


            Tom

            • 3. Re: CMR question
              dsundstrom

              I don't use these types of tools, but most people use XDoclet. There is an example of each CMR type in the JBossCMP documentation available from FlashLine ($10). There will example of 1:n and n:n relationship mappings in the final quick start guide, which should be coming out within a week.

              • 4. Re: CMR question
                garymarsh

                Hi tinnes;

                Did you ever get this thing figured out? I am using JBuilder6 and I'm having the same problem with my 1-to-1 relationship CMR. My posted thread is at
                http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ Marsh

                • 5. Re: CMR question
                  noel.rocher

                  Hi guys !

                  I had this problem. It 's that you must understand the way to think when you describe your relations.

                  Here is something that will help you :

                  =================================================
                  <!-- Company-Division -->
                  <ejb-relation>
                  <ejb-relation-name>Company-Division</ejb-relation-name>
                  <foreign-key-mapping/>
                  <ejb-relationship-role>
                  <ejb-relationship-role-name>Company-is-in-Division</ejb-relationship-role-name>
                  <key-fields/>

                  </ejb-relationship-role>

                  <ejb-relationship-role>
                  <ejb-relationship-role-name>Division-has-Companies</ejb-relationship-role-name>
                  <key-fields>
                  <key-field>
                  <field-name>id</field-name>
                  <column-name>division_id</column-name>
                  </key-field>
                  </key-fields>
                  </ejb-relationship-role>
                  </ejb-relation>
                  ================================================

                  You describe the field name of the EJB from the ONE side of the relation that correspond to the column foreign key of the table in the MANY side of the relation.

                  Hope this help. ;o)

                  Noel

                  • 6. Re: CMR question

                     

                    "noel.rocher@jboss.com" wrote:
                    Hi guys !

                    I had this problem. It 's that you must understand the way to think when you describe your relations.

                    Here is something that will help you :

                    =================================================
                    <!-- Company-Division -->
                    <ejb-relation>
                    <ejb-relation-name>Company-Division</ejb-relation-name>
                    <foreign-key-mapping/>
                    <ejb-relationship-role>
                    <ejb-relationship-role-name>Company-is-in-Division</ejb-relationship-role-name>
                    <key-fields/>

                    </ejb-relationship-role>

                    <ejb-relationship-role>
                    <ejb-relationship-role-name>Division-has-Companies</ejb-relationship-role-name>
                    <key-fields>
                    <key-field>
                    <field-name>id</field-name>
                    <column-name>division_id</column-name>
                    </key-field>
                    </key-fields>
                    </ejb-relationship-role>
                    </ejb-relation>
                    ================================================

                    You describe the field name of the EJB from the ONE side of the relation that correspond to the column foreign key of the table in the MANY side of the relation.

                    Hope this help. ;o)

                    Noel


                    This is not working for me because i have a composite primary key in both sides.