-->
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.  [ 1 post ] 
Author Message
 Post subject: Does Hibernate.initialize() be called implicitly?
PostPosted: Mon Nov 15, 2004 2:20 pm 
Regular
Regular

Joined: Thu Jul 01, 2004 12:13 am
Posts: 68
Location: San Diego, CA
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


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

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.