-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Lazy initializing object graph with varying subclasses
PostPosted: Wed Mar 03, 2004 11:35 am 
Newbie

Joined: Wed Mar 03, 2004 11:22 am
Posts: 12
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 1:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can't see any good solution for that
You could do 2 request, one for each subclasses but you'd need to know those subtypes.

The other solution is to read the Hibernate metadata to have a generic mecanism that Hibernate.initialize() needed parts.

Last part, use a slightly different mapping/sessionFactory for such request.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.