I am trying to write a routine to inflate (or hydrate) a partial graph; however, when I touch the nodes they *all* automatically hydrate. Could any of the following hibernate calls that use object cause the object to inflate without explcitly calling Hibernate.initialize()?
Code:
public void lazyInflateDeep(final SessionFactory sesFactory, Object object,
Set inflatables) throws DaoException {
try {
Class objClass = object.getClass();
ClassMetadata classMetadata = sesFactory.getClassMetadata(objClass);
if (classMetadata == null) {
// If here, then we are dealing with a CBLIB Proxy class and
// must use the ProxyHelper to get the proxied class
objClass = HibernateProxyHelper.getClass(object);
classMetadata = sesFactory.getClassMetadata(objClass);
}
// get persistent properties
Type[] propertyTypes = classMetadata.getPropertyTypes();
String[] propertyNames = classMetadata.getPropertyNames();
// for each persistent property of the bean
for (int i = 0; i < propertyTypes.length; i++) {
if (propertyTypes[i].isPersistentCollectionType()) {
CollectionMetadata collectionMetadata = sesFactory
.getCollectionMetadata(((PersistentCollectionType) propertyTypes[i])
.getRole());
String propName = propertyNames[i];
Collection collection = (Collection) classMetadata
.getPropertyValue(object, propName);
if (collection != null && !collection.isEmpty()) {
if (collectionMetadata.isLazy()
&& !Hibernate.isInitialized(collection)) {
if (inflatables.contains(propName)) {
Hibernate.initialize(collection);
log.info("Inflating: " + propName);
}
}
recurseAndInflateGraph(sesFactory, collection, inflatables);
}
} else if (propertyTypes[i].isAssociationType()) {
String propName = propertyNames[i];
Object association = classMetadata
.getPropertyValue(object, propName);
if (association != null ) {
if (!Hibernate.isInitialized(association)) {
if (inflatables.contains(propName)) {
Hibernate.initialize(association);
log.info("Inflating: " + propName);
}
}
}
}
}
} catch (HibernateException he) {
log.warning("Hibernate Exception thrown: " + he);
throw new DaoException(he);
}
}
Thanks,
Lou