0 Replies Latest reply on Jan 19, 2005 6:22 AM by mandarjboss

    Problems in establishing 1:1 self relationship

    mandarjboss Newbie

      I have an entity beans(CMP) QuestionCategories .
      I am trying to establish a one to one self relationship.
      I am deploying my EJBs on JBoss 3.2.6

      Here are my XML configuration files...
      <ejb-relation>
      <ejb-relation-name>ParentQuestionCategories- ChildQuestionCategories</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>ParentQuestioncategory
      </ejb-relationship-role-name>
      One
      <cascade-delete />
      <relationship-role-source>
      <ejb-name>QuestionCategories</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>ChildQuestionCategory
      </ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>QuestionCategories</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>parentcategory</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      <ejb-relation>

      In my jbosscmp-jdbc.xml I have
      <ejb-relation-name>ParentQuestionCategories-ChildQuestionCategories
      </ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>ParentQuestioncategory
      </ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>ChildQuestionCategory
      </ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>questionCategoryID</field-name>
      <column-name>QuestionCategoryID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>QuestionCategories-Questions</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>questioncategories
      </ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>questions
      </ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>questionCategoryID</field-name>
      <column-name>QuestionCategoryID</column-name>
      </key-field> </key-fields>
      </ejb-relationship-role>
      </ejb-relation>

      In database i have constraint definition as

      ALTER TABLE QUESTION_CATEGORIES ADD (
      CONSTRAINT FK_QUESTIONCATEGORIES FOREIGN KEY (PARENTCATEGORY)
      REFERENCES QUESTION_CATEGORIES (QUESTIONCATEGORYID));

      Whenever I am calling the CMR method getParentcategory() on my QuestionCategories instance i am getting a Local object for the same entity bean from which i am calling method.
      e.g. If i have an entity bean instance for categoryId =2 whose parent is 1.
      When i am calling method "getParentcategory" on Local object of
      categoryId = 2 I am getting the same instance back
      i.e (getParent().getCategoryID = 2...again which should actually be 1).