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.  [ 4 posts ] 
Author Message
 Post subject: Three-level association won't eager fetch
PostPosted: Fri Oct 28, 2005 2:51 am 
Newbie

Joined: Thu Oct 27, 2005 11:42 pm
Posts: 5
I have a three-level set of associations: A GolfCourse has many Teesets, and each Teeset has many Ratings. I'd like to be able to join the Ratings to the Teesets during fetch, but I can't get it to happen. Setting the fetch to subselect works fine, but setting it to join seems to do the same thing as select (the default).

I also tried
List result = HibernateUtil.getSession().createCriteria(GolfCourse.class).setFetchMode("teesets.ratings", FetchMode.Join).list();
but that didn't work, either.

Thoughts?

Hibernate version:
3.0.5

Mapping documents:
<class name="com.teravation.golf.GolfCourse" table="course">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="name" type="text" column="name" />
<property name="description" type="text" column="description" />
<map name="teesets" table="teeset">
<key column="courseId" />
<map-key type="string" column="name" />
<one-to-many class="com.teravation.golf.Teeset" />
</map>
<list name="holes" table="hole">
<key column="courseId" />
<list-index column="number" base="1" />
<one-to-many class="com.teravation.golf.Hole" />
</list>
</class>

<class name="com.teravation.golf.Teeset" table="teeset" >
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="name" type="text" column="name" />
<map name="ratings" table="rating" fetch="subselect"> <!-- This should be a join, but it doesn't work! -->
<key column="teesetId" />
<map-key type="string" formula="golferType" />
<one-to-many class="com.teravation.golf.Rating" />
</map>
</class>

<class name="com.teravation.golf.Rating" table="Rating">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="course" type="double" column="course" />
<property name="slope" type="integer" column="slope" />
</class>

Code between sessionFactory.openSession() and session.close():
List result = HibernateUtil.getSession().createCriteria(GolfCourse.class).list();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
PostgreSQL 8.0

The generated SQL (show_sql=true):
With fretch set to join, it doesn't actually do the join (behaves as a select)

Hibernate: select this_.id as id0_, this_.name as name0_0_, this_.description as descript3_0_0_ from course this_
Hibernate: select teesets0_.courseId as courseId1_, teesets0_.id as id1_, teesets0_.name as name1_, teesets0_.id as id0_, teesets0_.name as name1_0_ from teeset teesets0_ where teesets0_.courseId=?
Hibernate: select ratings0_.teesetId as teesetId1_, ratings0_.id as id1_, ratings0_.golferType as formula0_1_, ratings0_.id as id0_, ratings0_.course as course2_0_, ratings0_.slope as slope2_0_ from Rating ratings0_ where ratings0_.teesetId=?
Hibernate: select ratings0_.teesetId as teesetId1_, ratings0_.id as id1_, ratings0_.golferType as formula0_1_, ratings0_.id as id0_, ratings0_.course as course2_0_, ratings0_.slope as slope2_0_ from Rating ratings0_ where ratings0_.teesetId=?
Hibernate: select ratings0_.teesetId as teesetId1_, ratings0_.id as id1_, ratings0_.golferType as formula0_1_, ratings0_.id as id0_, ratings0_.course as course2_0_, ratings0_.slope as slope2_0_ from Rating ratings0_ where ratings0_.teesetId=?
Hibernate: select ratings0_.teesetId as teesetId1_, ratings0_.id as id1_, ratings0_.golferType as formula0_1_, ratings0_.id as id0_, ratings0_.course as course2_0_, ratings0_.slope as slope2_0_ from Rating ratings0_ where ratings0_.teesetId=?
Hibernate: select holes0_.courseId as courseId1_, holes0_.id as id1_, holes0_.number as number1_, holes0_.id as id0_, holes0_.number as number3_0_ from hole holes0_ where holes0_.courseId=?
Hibernate: select tees0_.holeId as holeId2_, tees0_.id as id2_, tees0_.teesetId as formula1_2_, tees0_.id as id1_, tees0_.teesetId as teesetId4_1_, tees0_.distance as distance4_1_, tees0_.par as par4_1_, tees0_.handicap as handicap4_1_, teeset1_.id as id0_, teeset1_.name as name1_0_ from Tee tees0_ left outer join teeset teeset1_ on tees0_.teesetId=teeset1_.id where tees0_.holeId=?

With a subselect, though, it behaves as expected
Hibernate: select this_.id as id0_, this_.name as name0_0_, this_.description as descript3_0_0_ from course this_
Hibernate: select teesets0_.courseId as courseId1_, teesets0_.id as id1_, teesets0_.name as name1_, teesets0_.id as id0_, teesets0_.name as name1_0_ from teeset teesets0_ where teesets0_.courseId=?
Hibernate: select ratings0_.teesetId as teesetId1_, ratings0_.id as id1_, ratings0_.golferType as formula0_1_, ratings0_.id as id0_, ratings0_.course as course2_0_, ratings0_.slope as slope2_0_ from Rating ratings0_ where ratings0_.teesetId in (select teesets0_.id from teeset teesets0_ where teesets0_.courseId=?)
Hibernate: select holes0_.courseId as courseId1_, holes0_.id as id1_, holes0_.number as number1_, holes0_.id as id0_, holes0_.number as number3_0_ from hole holes0_ where holes0_.courseId=?
Hibernate: select tees0_.holeId as holeId2_, tees0_.id as id2_, tees0_.teesetId as formula1_2_, tees0_.id as id1_, tees0_.teesetId as teesetId4_1_, tees0_.distance as distance4_1_, tees0_.par as par4_1_, tees0_.handicap as handicap4_1_, teeset1_.id as id0_, teeset1_.name as name1_0_ from Tee tees0_ left outer join teeset teeset1_ on tees0_.teesetId=teeset1_.id where tees0_.holeId=?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 6:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
what is the value of the max_fetch_depth setting for the session factory?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 2:32 pm 
Newbie

Joined: Thu Oct 27, 2005 11:42 pm
Posts: 5
I have the following in hibernate.cfg.xml:
<!-- Max Fetch Depth for Joins -->
<property name="hibernate.max_fetch_depth">3</property>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 31, 2005 2:58 pm 
Newbie

Joined: Thu Oct 27, 2005 11:42 pm
Posts: 5
Is there some other way to set the fetch depth? It would be especially nice if I could do it via the setFetchMode("teesets.ratings", FetchMode.Join) route, as that would allow me to leave the global setting low, and only increase it on a per-query basis.


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

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.