Hi,
My issue is, I have a POJO which has a collection of other objects. I am exporting this POJO to XML using XStream and also setting Xstream to treat Hibernate collections as normal java collections using converters.
x.addDefaultImplementation(org.hibernate.mapping.List.class, java.util.List.class); x.addDefaultImplementation(org.hibernate.mapping.Map.class, java.util.Map.class); x.addDefaultImplementation(org.hibernate.mapping.Set.class, java.util.Set.class); x.addDefaultImplementation(org.hibernate.collection.PersistentSet.class, java.util.Set.class); x.addDefaultImplementation(org.hibernate.collection.PersistentSortedSet.class, java.util.Set.class); Mapper mapper = x.getMapper(); x.registerConverter(new HibernateCollectionConverter(mapper)); x.registerConverter(new HibernateMapConverter(mapper));
String xml = x.toXML("POJO Object");
Then I try to create an Object with XML and persist. I do like,
Object o = x.fromXML(xml);
then when I want to save object using hibernate, I get following error.
org.hibernate.HibernateException: could not reassociate uninitialized transient collection at org.hibernate.event.def.ProxyVisitor.reattachCollection(ProxyVisitor.java:70) at org.hibernate.event.def.WrapVisitor.processCollection(WrapVisitor.java:45) at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
Then I removed collection part from XML and try to save object. Hibernate saves object but when I try to add an item to collection, I get NullPointer exception as collection is assigned as null.
Please advise... Any suggestion would be greatly appreciated..
Thanks, Datta
|