Thanks for the grammar. Too bad it is not simply a BNF style grammar ;-) About the setFetchMode(). It appears as if this only works for direct properties although the JavaDoc for setFetchMode() says that the first parameter can be a dot separated property path.
Assume a table "course", with composity id ("schedule", "request"). "Request" has a one-to-many property "requestCustomers", and so on. If I now specify the required property paths like this...
Code:
courses = session.createCriteria(Course.class)
.add(Restrictions.ge("courseEnd", startDate))
.add(Restrictions.lt("courseEnd", endDate))
.setFetchMode("id.request", FetchMode.JOIN)
.setFetchMode("id.request.requestCustomers", FetchMode.JOIN)
.setFetchMode("id.request.courseTypeVersion.courseType.title",
FetchMode.JOIN)
.setMaxResults(15)
.list();
Course c = (Course) courses.get(0);
Request r = c.getId().getRequest();
Set rc = r.getRequestCustomers();
CourseType ct = r.getCourseTypeVersion().getCourseType();
String t = ct.getTitle();
...I still get extra selects when I access the data via these property paths - which is what I wanted to avoid (the list is to be looped and this would result in hundreds or thousands of separate select statements). What am I doing wrong? The SQL created by the above statement looks like this (it does not even reference the other tables, e.g. "Request"):
Code:
SELECT *
FROM ( /* criteria query */SELECT this_.schedule_key AS schedule1_0_,
this_.request_key AS request2_0_,
...
FROM course this_
WHERE this_.course_end >= ?
AND this_.course_end < ?)
WHERE ROWNUM <= ?