I have a object "
Person" which is linked one-to-many with some "
Contracts" objects and i use the Criteria API to initialize them.
If I use the API like it, the objets are well preloaded and it is ok:
Code:
Criteria criteriaPerson = hsession.createCriteria(Person.class);
criteriaPerson.setFetchMode("contracts",FetchMode.JOIN);
In this case, hibernate generate an left outer join in the query and i can access the contracts collection after closing the hibernate session.
But if i add a restriction in the query like this:
Code:
Criteria criteriaPerson = hsession.createCriteria(Person.class);
criteriaPerson.setFetchMode("contracts",FetchMode.JOIN);
criteriaPerson.createCriteria("contracts").add(Expression.isNotNull("endDate"));
In this case, hibernate generate an inner join in the query, and when i access the contracts collection after closing the hibernate session, i get a LazyInitializationException.
Any idea ?
PS: I don't want to define lazy loading properties in my xml files, cause i want to define lazy loading in the code with something like "setFetchMode("contracts",FetchMode.JOIN)".