Can someone please confirm that setFetchMode("threads.posts", FetchMode.JOIN) is a valid way to specify left outer join in the example I posted earlier?
In the meanwhile, I tried to assemble the criteria query slightly differently - see below. I thought that this would also fetch forums, threads and posts in one hit, but it doesn't - it actually makes two hits.
Code:
Criteria forumCriteria = getSession()
.createCriteria(Forum.class)
.add(Restrictions.idEq(forumId))
.setFetchMode("threads", FetchMode.JOIN);
forumCriteria
.createCriteria("threads")
.setFetchMode("posts", FetchMode.JOIN);
return (Forum)forumCriteria.uniqueResult();
Here are the two hits to the database:
Code:
select ...
from FORUM
this_ inner join THREAD threadimpl1_ on this_.ID=threadimpl1_.FORUM_FK
left outer join POST posts4_ on threadimpl1_.ID=posts4_.THREAD_FK
where this_.ID = ?
order by posts4_.THREAD_FK
select ...
from THREAD threads0_
where threads0_.FORUM_FK=?
order by threads0_.FORUM_FK
Can anyone tell why this version generates two queries? Also why is thread joined with inner join instead of outer join?
Thanks.
Naresh