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
|