This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Hibernate - Object Graph using outer join  RSS feed

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to create Object Graph from three (or more) related tables by querying it with criteria. I have learnt that using left join fetch we can do it in single query but it seems there are certain limitations.


I have following mappings:

Question.hbm.xml
<class name="Question" table="QUESTION">
<id name="questionId" type="java.lang.Long" column="QUESTIONID" >
<generator class="increment" />
</id>
<property name="questionName" type="java.lang.String" column="QUESTIONNAME" length="500" />
<many-to-one name="questionType" column="QUESTIONTYPEID" class="QuestionType"/>
<many-to-one name="questionSet" column="QUESTIONSETID" class="QuestionSet" not-null="true" fetch="join"/>
<one-to-one name="comment" class="Comment" property-ref="question" cascade="all"/>
<one-to-one name="matrix" class="Matrix" property-ref="question" cascade="all"/>
<bag name="answers" inverse="true" cascade="all, delete-orphan" lazy="false">
<key column="questionId"/>
<one-to-many class="Answer"/>
</bag>
<bag name="matrix" inverse="true" cascade="all, delete-orphan" lazy="false">
<key column="questionId"/>
<one-to-many class="Matrix"/>
</bag>
<bag name="features" inverse="true" cascade="all" lazy="false">
<key column="questionId"/>
<one-to-many class="Feature"/>
</bag>
<bag name="rules" cascade="all" lazy="false">
<key column="questionId"/>
<one-to-many class="Rule"/>
</bag>
</class>


Answer.hbm.xml:

<class name="Answer" table="ANSWER">
<id name="answerId" type="java.lang.Long" column="ANSWERID" >
<generator class="increment" />
</id>
<property name="answerName" type="java.lang.String" column="ANSWERNAME" length="50" />
<many-to-one name="question" column="questionId" class="Question" not-null="true" fetch="join"/>
<bag name="features" cascade="all" lazy="false">
<key column="ANSWERID"/>
<one-to-many class="Feature"/>
</bag>
</class>



Similar way Features.hbm.xml and Rules.hbm.xml. Now, I want to pass questionSetId (parent) and bring all the records in the collection and do the processing...

1) Is this preferred approach?

2) If yes, then it fires lots of queries. Should I fire explicit queries and create Object Graph manually? How can I avoid lots of queries and create Object Graph in one (or minimal) query.

3) If no, can you advice me for preferred approach in this example?

I am using Table per Concrete Class approach.


Thanks,
Bhavin




Thanks,
Bhavin
[ December 09, 2008: Message edited by: Bhavin Sanghani ]
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone advice me on this?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!