These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: XStream/Hibernate Save object
PostPosted: Tue Aug 11, 2009 9:09 am 
Newbie

Joined: Wed Aug 05, 2009 9:52 am
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.