• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

EJB : CMR

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
<multiplicity>One</multiplicity>
<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>
<multiplicity>One</multiplicity>
<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).
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Java From Mandar",
We're pleased to have you here with us in the EJB forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Forum Bartender
 
Mandar_Kulkarni
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne,
Ya sure I am changing my display name.
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Mandar_Kulkarni",
Thanks. We request display names to be two names (first and last.) Could you just change the underscore to a space?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both of your relationships in the jboss-jdbc.xml descriptor specify the same key-field: QuestionCategoryID. I don't know JBoss, but logically shouldn't one of them specify PARENTCATEGORY (DB column) and parentcategory (CMR field)?

The way you have it, the behavior you're seeing makes sense as two entities are related by their primary key. Clearly this results in each entity being related to itself.
 
What's that smell? Hey, sniff this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic