-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to tell what's been lazily loaded, without loading more?
PostPosted: Fri Apr 16, 2004 7:25 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
We have a new system we're developing on a JDK 1.4 app server, and we want to expose its stateless-session-bean service layer to a legacy system running JDK 1.3. Hence we can't use plain old RMI because of all kinds of horrible serialization versioning problems.

"Use SOAP," you say! Hah, if only. Axis is still a big ball of hair and we want to stay open source in our whole stack if we can and until we must do otherwise. (We're using JOnAS for our app server, which integrates Axis.)

So I've written a small reflection-based layer around XML-RPC, and we're using that. Seems to work pretty well. Except....

When using RMI, and when we serialize a Hibernate collection, the collection intelligently serializes itself to send over only the contents that have been loaded thus far. In other words, serializing the Hibernate collection won't force lazy loading.

However, my little reflection wrapper doesn't have the benefit of that, and when it goes to traverse the collection (to flatten the contents into a form XML-RPC can handle), it goes and gets a LazyInitializationException since I don't have a session at the point where the traversal is happening. And I don't even WANT to traverse the collection; I only want to flatten the contents that have been loaded thus far (if any). In other words, I already have code that loads only the parts of the dependent graph that I care about; I just want to be able to know *which parts those are* without forcing any further lazy loading.

Is this possible? Any under-the-hood hooks in the Hibernate collections for detecting / enumerating only what's actually been loaded? Anyone else run into similar problems? (I can only assume that anyone working with SOAP or any other non-RMI serialization would have run into this as well....)

Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 8:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Hibernate.isInitialized()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 8:40 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Thanks!

This seems to work as well:
Code:
        if (hydratedObject instanceof PersistentCollection) {
            // iterate the entries!  avoids lazy loading.
            try {
                Iterator iter = ((PersistentCollection)hydratedObject).entries();
                while (iter.hasNext()) {
                    Object o = (Object) iter.next();
                    state.add(XmlRpcHelper.dehydrate(o, context));
                }
            } catch (NullPointerException ex) {
                // the collection is totally uninitialized!
                // TODO: is there a way to CHECK?!
                log.warn("PersistentCollection.entries threw NPE; assuming empty.");
                // and do nothing!  we WANT an empty collection here.
            }

Not as elegant, though :-)

Also, is it possible that a collection could be initialized but only *partially* lazy-loaded, and that in that case isInitialized() would return true but iterating would still force further lazy loading (which, as I said, is not what I want)? I *know* that calling "entries()" will never force any lazy loading.

Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 8:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No, a proxied collection will never be partially loaded.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.