It is possible to have lazy loading optional at runtime? I would like to have method on state less session bean (SLSB), where one parameter is: boolean lazyLoding
If I set lazyLoding=false, I would like to get all object graph from method of SLSB, when I set lazyLoading=true, I would like to retrieve only "first level of data", only object with its properties, not related classes, collections...
EXAMPLE of method I would like to implement:
In POJOs I have hibernate tag:
Code:
* @hibernate.class table="XXX_TBL" proxy="com.domainmodel.Xxx"
Code:
public List findPOJOS(boolean lazyLoading, String sQuery) throws ExceptionDAO {
List results = null;
Session session = getSession();
try {
results = (List) session.find(sQuery);
if (!lazyLoading) {
// here I don't know how to write generic code
// begin - this code is not ok
for (int i = 0; i < results.size(); i++) {
Object o = (Object) results.get(i);
Hibernate.initialize(o);
// here should come recursion to initialize
// all objects in graph
}
// end - this code is not ok
}
} catch (HibernateException he) {
he.printStackTrace();
throw new ExceptionDAO(he);
} finally {
closeSession(session);
}
return results;
}