• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Hibernate - Object Graph using outer join

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone advice me on this?
 
I do some of my very best work in water. Like this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic