5 Replies Latest reply on Mar 9, 2004 2:19 AM by Sebastiaan Kortleven

    CMR with EJB2.0 + JBoss3.2

    mandarjboss Newbie

      I am trying to implement the CMR relationship between a QuestionBean and a ChoiceBean.There is one-to-one realtionship between these two entity beans.I have following portion of deployment descriptor created by XDoclet for me.

      <!-- Relationships -->

      <ejb-relation >
      <ejb-relation-name>Question-Has-A-Choices</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>Question-of-Choices
      </ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>Question</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>choices</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>Choices-Of-A-Question</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>Choice</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      </ejb-relation>




      The main problem is if i execute the application with tables created by me the it gives me the error,
      "Relation Question does not have choices field".
      However when i allow JBoss to auto-create the tables then the application works.But now I can see a field like "choices" created in question table.As per my knowledge of EJB you do not have to declare getter and setter methods for CMR field.Strngely I can see the similar values in Choices CMR field of question table and choiceid of Choices table.

      My table structure is,

      Question
      q_id
      q_text
      r_ans

      AND

      Choice
      Ch_id
      q_id
      choice1
      choice2
      choice3

      Can someone help me please?

        • 1. Re: CMR with EJB2.0 + JBoss3.2
          sesques Novice

          Look at the jbosscmp-jdbc.xml the <key-fields> tag corresponding to your relationship role name

          If you cannot find the problem, post the file

          I hope this helps you

          • 2. Re: CMR with EJB2.0 + JBoss3.2
            mandarjboss Newbie

            Hi sesques,
            Thanx for ur reply.I really could not figure out the problem.
            Well I have now changed the database schema as

            Question
            q_id
            q_text
            rightChoice
            choiceid

            Choice
            choiceid
            choice1
            choice2
            choice3


            Well the portion of ejb-jar.xml is not much different.

            As u can see from the database structure i want my choiceid column in Question table to act as a Foreign-key for Choice table's choiceid primary key.
            Even after these settings the same problem which i have mentioned above still persists.JBoss is still creating a new Field "Choices" probably corresponding to "ChoicesLocal getChoices()".But this is a CMR field then why does JBOss creates a column for that field..?
            Really cant understand.Please help me.
            Here is a snippet of jbosscmp-jdbc.xml generated by XDoclet for me.


            <ejb-relation>
            <ejb-relation-name>Question-Has-A-Choices</ejb-relation-name>

            <ejb-relationship-role>
            <ejb-relationship-role-name>Question-Of-A-Choice
            </ejb-relationship-role-name>
            <key-fields/>
            </ejb-relationship-role>

            <ejb-relationship-role>
            <ejb-relationship-role-name>Choices-Of-A-Question
            </ejb-relationship-role-name>
            <key-fields>
            <key-field>
            <field-name>choiceid</field-name>
            <column-name>choiceid</column-name>
            </key-field>
            </key-fields>
            </ejb-relationship-role>

            </ejb-relation>

            • 3. Re: CMR with EJB2.0 + JBoss3.2
              Sebastiaan Kortleven Newbie

              try this in your jbosscmp-jdbc.xml file:

              <ejb-relation>
              <ejb-relation-name>Question-Has-A-Choices</ejb-relation-name>

              <ejb-relationship-role>
              <ejb-relationship-role-name>Question-Of-A-Choice
              </ejb-relationship-role-name>
              <key-fields/>
              </ejb-relationship-role>

              <ejb-relationship-role>
              <ejb-relationship-role-name>Choices-Of-A-Question
              </ejb-relationship-role-name>
              <key-fields>
              <key-field>
              <field-name>choices</field-name>
              <column-name>choiceid</column-name>
              </key-field>
              </key-fields>
              </ejb-relationship-role>

              </ejb-relation>

              • 4. Re: CMR with EJB2.0 + JBoss3.2
                mandarjboss Newbie

                Thanx a....Lot aquilla125 it seems that your logic is working.You are extremely intellegent.
                Can u help me regarding the problem of auto-increment of primary key with Jboss3.2 and PostgreSQL7.3 ?

                • 5. Re: CMR with EJB2.0 + JBoss3.2
                  Sebastiaan Kortleven Newbie

                  I don't consider myself more intelligent then the next guy, but I've been sweating over the same problems these last few weeks :)

                  About your problem with the auto-increment... are you sure you added the <auto-increment/> tag to the correct fields in jbosscmp-jdbc.xml?
                  Also, in the default section add this tag:

                  <entity-command name="postgresql-fetch-seq"/>