fwiw, there's some code in the xstream jira which i found helpful for marshalling hibernate persistent collections:
http://jira.codehaus.org/browse/XSTR-226
there's a tiny bug in the HibernateCollectionMarshaller class tho. I had to patch as follows:
Code:
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
Object collection = source;
if (source instanceof PersistentCollection) {
PersistentCollection col = (PersistentCollection)source;
col.forceInitialization();
collection = col.getCollectionSnapshot().getSnapshot();
}
// the set is returned as a map by Hibernate (unclear why exactly)
if (source instanceof PersistentSet) {
collection = new HashSet(((HashMap)collection).values());
}
// delegate the collection to the approapriate converter
if (listSetConverter.canConvert(collection.getClass())) {
listSetConverter.marshal(collection, writer, context);
return;
}
if (mapConverter.canConvert(collection.getClass())) {
mapConverter.marshal(collection, writer, context);
return;
}
if (treeMapConverter.canConvert(collection.getClass())) {
treeMapConverter.marshal(collection, writer, context);
return;
}
if (treeSetConverter.canConvert(collection.getClass())) {
treeSetConverter.marshal(collection, writer, context);
return;
}
defaultConverter.marshal(collection, writer, context);
}
Costin had entrySet() instead of values() in the PersistentSet case. I also wonder why hibernate is returning a Map instead of a Set when you call getSnapShot() on the PersistentSet, perhaps a hibernate guru can explain?