-->
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.  [ 2 posts ] 
Author Message
 Post subject: Serializing PersistentBag
PostPosted: Thu Feb 05, 2009 8:00 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2009 1:24 am
Posts: 20
I use Lists everywhere in my code. I'm sure I don't have to explain why. The problem though is everytime I serialize an object as XML that comes out of hibernate that contains a List it gets spit out as total garbage. For instance... an object containing a List of locations results in:

Code:
<locations class="org.hibernate.collection.PersistentBag">
    <initialized>false</initialized>
    <owner class="zone" reference="../.."/>
    <cachedSize>-1</cachedSize>
    <role>locations</role>
    <key class="long">1</key>
    <dirty>false</dirty>
  </locations>


This is completely useless for me since it doesn't contain any of the information in the actual list. So, how do I get a REAL list out of hibernate? One that I can actually do something with that won't look like a mess when its serialized? I've searched all over the net for an answer to this one. I find lots of complaints about it but no actual solutions. I'm hoping someone has solved it here.

Thanks for all the help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 11:06 am 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Hibernate dynamically changes classes using proxy classes. What your seeing is the proxy class in the xml output. I could be wrong here but it looks like your list has not been loaded from the database yet. I would try setting your fetch to eager. Or call the method on the object that gets your list.

It's not really a problem with hibernate but the code you are using to serialize your object. There is a lot of information on the internet about this and a lot of ways around it. Just look up serializing hibernate proxy classes or something similar.

http://www.mojavelinux.com/blog/archive ... f_my_pojo/

I have a open source project which is still in early stages which uses the jpa annotations to get around this problem. Feel free to take a look at it and take any ideas from it.

http://sourceforge.net/projects/proselyte/


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

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.