Hibernate version:3.2.3
Great software, great documentation, great book (JPA w Hibernate), but it seems i am not smart enough to understand:
I have a question about eager fetching. I am looking at it the whole day and just need some clarification on the reference documentation (and JPA with Hibernate, too).
my mapping with fetch="join"
Code:
<class name="Member" table="member">
<id ... />
<property name="name" not-null="true" />
<set name="articels" fetch="join" table="articles">
<key column="member_id" not-null="true" />
<one-to-many class="Article" />
</set>
</class>
And now i read 13.2.3, p. 578 Eager fetching with joins.
and of course the reference documentation which says:
Quote:
The fetch strategy defined in the mapping document affects:
* retrieval via get() or load()
* retrieval that happens implicitly when an association is navigated
* Criteria queries
* HQL queries if subselect fetching is used
Now i try this:
Code:
public void testFetchJoin () {
Member member = memberRepository.findMemberById(9L);
member.getName();
}
and it works. It load() a member and all his articles are loaded
too by an outer join. Fine! Next try:
Code:
public void testFetchJoin2 () {
Forum forum = forumRepository.findbyId(1L);
forum.getMembers().iterator().next().getName();
}
Hibernate does
not load all articles of all members.
I thought, by setting fetch="join" i can assume that the whole non-lazy
object graph is held in memory.
It is the intended behaviour not to load all articles of all members if the whole set is initalized??
If yes, does it mean that calling iterator() on a set is not something to be called "retrieval that happens implicitly when an association is navigated"?
I would really appreciate your help.
kind regards,
janning
PS: As it is a question about clarification of documentation i didn't put all my code into here as advised by the "New Topic form". If this was wrong, please blame me! But i thought about it and came to conclusion that my problem is more understandable without it.