I have a need to read a complete object graph starting from a certain class. (including lazy collections) I do need to use lazy collections, as loading the entire object graph is not the normal behavior of the application.
As an example, let's say that I want to load an Office object. The Office class contains a collection of employees that is lazy initialized. The Employee class is subclassed by Manager and Schmuck. Manager contains a collection of subordinates that is lazy initialized, but Schmuck doesn't.
So I want to retrieve the Office object graph with all lazy collections initialized.
Correct me if I am wrong, but I can't do this with a "join fetch" because not all employees have the "subordinates" property. I could retrieve the office, loop through all employees, and for the ones that are "instanceof" Manager, call Hibernate.initialize() to initialize their subordinates.
However, in my real-world situation, importing the subclass of "Employee" creates unwanted module dependencies. In other words, I would have to know all subclasses of Employee and my module where the Hibernate code exists must depend on every other module that has a subclass of Employee.
What I would really like is either:
a) a way to turn off lazy collections altogether temporarily for a particular Session.
b) a way to "join fetch" only for certain subclasses of a class
c) another solution that doesn't force me to create a dependency on the subclass of Employee.
Thanks,
Jeremy
Hibernate version: 2.1.2
Using PostgreSQL: 7.3.2
|