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:
|