I have to modify a large Hibernate DetachedCriteria query to fetch some additional associations.
My object graph resembles the structure below, I want to fetch the sales associated with each Car:
<class name="Showroom" table="showroom">
...
<bag name="cars" lazy="false">
<one-to-many class="Car" />
</bag>
...
</class>
<class name="Car" table="car">
...
<set name="sales" lazy="true">
<one-to-many class="Sale" />
</set>
...
</class>
What I want to do is something like:
DetachedCriteria criteria = DetachedCriteria.forClass(Showroom.class);
// ... Existing criteria query code ...
criteria.setFetchMode("cars.sales", FetchMode.JOIN);
But the associationPath argument in setFetchMode seems to ignore the dot notation and I get a LazyInitializationException:
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: Car.sales, no session or session was closed
I've search around and so far found no examples or information. The Hibernate documentation does not provide examples on how to fetch nested associations, and the Javadoc for setFetchMode seems to suggest that my dot-notation approach should have worked...
Any help would be appreciated.