Forums Register Login

EJB : CMR

+Pie Number of slices to send: Send
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).
+Pie Number of slices to send: Send
"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
+Pie Number of slices to send: Send
Hi Jeanne,
Ya sure I am changing my display name.
+Pie Number of slices to send: Send
"Mandar_Kulkarni",
Thanks. We request display names to be two names (first and last.) Could you just change the underscore to a space?
+Pie Number of slices to send: Send
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.
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 710 times.
Similar Threads
cascade-delete doesn't work
Help me out for EJB2.0 CMR fields mapping in XDOCLET.......
one-to-one relationship
How to Rollback Transaction in EJB2.0?
Weblogic - EJB 2.0 CMR Relationship eager loading ??
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:57:36.