Consider the following three Hibernate entities:
public class Car {
@OneToMany(fetch = FetchType.LAZY)
@Fetch(FetchMode.SUBSELECT)
private List<Wheel> wheels;
}
public class Wheel {
@OneToOne(fetch = FetchType.LAZY)
private Hubcap hubcap;
}
public class Hubcap {
}
Consider the following Criteria:
Criteria criteria = getSession().createCriteria(Car.class);
List<Car> cars = criteria.list();
for (Car car : cars) {
Hibernate.initialize(car.getWheels());
}
Is there any way to control the subselect query that will be generated? Specifically I'd like to join in the subselect so that the hubcaps are also fetched when the wheels are fetched. This can of course be accomplished by changing the FetchType to EAGER, but I need something more ad hoc - on a query by query basis.
As the code is currently I'd need to generate another select to fetch the Hubcaps.