-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using fetch="join"strategy not working for nested
PostPosted: Wed Oct 29, 2008 4:59 pm 
Newbie

Joined: Sun Sep 07, 2008 11:07 pm
Posts: 17
Hibernate version:[3.2]

Name and version of the database you are using:Oracle10G


I have 3 classes say
Form
Questions
AnswerOptions

The relationship from Form to Questions is one-many
The relationship from Questions to Answeroptions is one-many

Form.hbm.xml

<class name="Form" table="FORM">
...
<bag name="questions" inverse="true" cascade="all" >
<key>
<column name="PACKAGE_NUM" precision="22" scale="0" not-null="true" />
<column name="VERSION_SEQ" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="Question" />
</bag>
</class>

Question.hbm.xml

<class name="Question" table="QUESTION">
..
<bag name="answerOptions" inverse="true" lazy="false" fetch="join" cascade="all">
<key column="QUESTION_ID" not-null="true"/>
<one-to-many class="AnswerOptions" />
</bag>
</class>

AnswerOption.hbm.xml

<class name="AnswerOptions" table="ANSWER">
...
<many-to-one name="question" class="Question" fetch="join">
<column name="QUESTION_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
</class>


I have the following code

Form form = (Form)session.get(Form.class, identity); // It fires the
//Select query from the Form table and does not load collections as
//Questions are lazy loaded (Correct)
List questions = form .getQuestions();
Question ques = questions.get(0); // It fires the query to get the Question and then it fires multiple select statements to get the AnswerOptions. (Wrong)

why mutliple select statements are fired even though I have specified fetch="join" and lazy="false" in my Question mapping file.

But If I read direclty the Question with the QuestionId it works
Question ques = (Question)session.get(Question.class,identity)
//This fires the select Question query by making an outer join query with Answeroptions

Please advice me


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.