XStream and Hibernate lazy loading issues

Posted on May 9, 2011


If you are marshalling persistent objects being managed by Hibernate, you will have issues with Lazy loading.

Say you have

Order class with an property which is Product class type or List of OrderItem objects … instanceof match will fail (even if you have your own Custom Converter) … as the instance will be OrderItems_javaassist_xxx etc. (even if you access the properties to load the properties).

The simple solution is to explicity invoke .toXML for the property. I found more complex solutions using reflection here. I went with the first approach.

If you find better solutions do let me know.

Posted in: Hibernate, XStream