Hi,
We are getting LazyInitializationExceptions when marshalling an object graph 
read from a DB by Hibernate to XML.
We deliberately do not load certain parts of the graph because we do not ever 
want to see that data.  Unfortunately
when JiBX tried to iterator over the Set (which is really a Hibernate 
PersistentSet) Hibernate tries to load the uninitialized data
but the Hibernate session has long since been closed.

I would like to create a global custom marshhaller that would skip the 
collection if it uninitialized. This appeared
easy to do so I wrote:
     public class PersistentSetMapper {
        public void marshal(Object obj, IMarshallingContext ctx)
                        throws JiBXException {

                PersistentSet pset = (PersistentSet) obj;
                if (!pset.wasInitialized()) {
                        return;
                }
                for (Object ele : pset) {
                        if (ele instanceof IMarshallable) {
                                ((IMarshallable) ele).marshal(ctx);
                        }
                }
        }
     }

And added it at the top of my binding definition:

<mapping class="org.hibernate.collection.PersistentSet" name="pset"
   marshaller="PersistentSetMapper"/>

I have not been able to try this because I get an error saying you can't call 
out a custom
marhshaller unless you also have a custom unmarshaller.

Q: Am I on the right track here? Is there a better, easier way of doing this?
Q: How can I create a custom unmarshaller that just does exactly what the 
standard marshaller
would have done for the collection?

Thanks, - Jon





-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to