If you are doing HQL, you can use the “left outer join” or “left join” to join the association you want, rather than lazy loaded ones, for example.
If you have a Building class that has a property that returns an Address object, and this relationship will be lazy, you can have HQL similar to:
string hql = "from Building bld where bld.Type.Id = 1";
When using the Address property, a different SQL statement will be executed for each building. Changing HQL to the following will extract the addresses as part of the original SQL statement:
string hql = "from Building bld left outer join fetch bld.Address as addr where bld.Type.Id = 1";
source share