I\'ve been facing this issue where, the hibernate objects on serialization produces unexpect xmls containing all the instrumented code from Hibernate.
We did some cleani
I've not used XStream before, but I have serialized Hibernate-managed entities. It isn't fun.
There are two big issues:
The former is obvious - you need the actual data to serialize. The latter is less so - any one-to-many relationships you declare against collection interfaces (eg: Set
) will get plugged by Hibernate's own (unserializable!) collection implementations. This may well be where Hibernate's classes are bleeding into your objects.
I ended up writing reflective code (actually introspective) that did this:
Note that step 2 is important - if you replace the collections prior to closing the session, Hibernate will just put its own collections right back upon close...
Edit: @cliff.meyers spotted a detail of the implementation I forgot to mention: if you do this, you need to limit object graph walking only to your own entities, and watch for circular reference paths (eg: by caching references to objects you've already walked).