Well, I don't know what to say but I actually tried this out and I think I found the same thing.
I tried to set the fetch mode to eager on a many-to-one + "." + one-to-many and I got a init exception when trying to check the size.
I tried the same thing where I loaded up the many side and then specified a EAGER fetch mode and was able to call size() on it with no issue.
This blew a lazy init exception.
Code:
public void test() throws Exception {
Session session = HibernateConfigurationHelper.getSession();
Criteria criteria = session.createCriteria(Analysis.class);
criteria = criteria.setFetchMode(Analysis.NOTES_PROPERTY + "." + Note.NOTE_DETAILS_PROPERTY, FetchMode.JOIN);
List results = criteria.list();
session.close();
for (Iterator it = results.iterator(); it.hasNext();) {
Analysis analysis = (Analysis) it.next();
System.out.println("analysis = " + analysis.getAnalysisId());
if (analysis.getNotes() != null) {
System.out.println(analysis.getNotes().getNoteDetails().size());
}
}
}
This did not.
Code:
public void test2() throws Exception {
Session session = HibernateConfigurationHelper.getSession();
Criteria criteria = session.createCriteria(Notes.class);
criteria = criteria.setFetchMode(Note.NOTE_DETAILS_PROPERTY, FetchMode.JOIN);
List results = criteria.list();
session.close();
for (Iterator it = results.iterator(); it.hasNext();) {
Note note = (Note) it.next();
System.out.println("note = " + note.getNotesId());
System.out.println(note.getNoteDetails().size());
}
}
Don't know what to say but the java doc still implies that its main use is to specify outer joinability at run time.
"Specify an association fetching strategy for a one-to-many, many-to-one or one-to-one association, or for a collection of values. "