-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem converting Hibernate POJOs to XML
PostPosted: Wed Jul 05, 2006 3:13 pm 
Newbie

Joined: Tue Jul 19, 2005 1:28 pm
Posts: 17
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

3.x:

Hi,

I am facing a problem converting Hibernate objects (i.e. POJOs) to XML. I am using XStream to convert the objects into XML, but when I pass the object to XStream, it does'nt seem to find the actual fields but gives some other fields with even the class name suffixed with something like "EnhancerByCGLIB--411188b1 resolves-to="org.hibernate.proxy.SerializableProxy"

Here is an example of the XML output given by XStream

<edu.utd.eplan.business.objects.Facility--EnhancerByCGLIB--411188b1 resolves-to="org.hibernate.proxy.SerializableProxy">
<entityName>edu.utd.eplan.business.objects.Facility</entityName>
<persistentClass>edu.utd.eplan.business.objects.Facility</persistentClass>
<interfaces>
<java-class>org.hibernate.proxy.HibernateProxy</java-class>
</interfaces>
<id class="int">2</id>
<getIdentifierMethodClass>edu.utd.eplan.business.objects.Facility</getIdentifierMethodClass>
<setIdentifierMethodClass>edu.utd.eplan.business.objects.Facility</setIdentifierMethodClass>
<getIdentifierMethodName>getFacilityId</getIdentifierMethodName>
<setIdentifierMethodName>setFacilityId</setIdentifierMethodName>
<setIdentifierMethodParams>
<java-class>java.lang.Integer</java-class>
</setIdentifierMethodParams>
</edu.utd.eplan.business.objects.Facility--EnhancerByCGLIB--411188b1>

If I take a plain POJO without associating it with Hibernate Session i.e. I manually populate the fields, I get the correct XML output depicting the actual fields and their values.

I am using Hibernate framework with Spring framework. From the above output it seems that Hibernate is modifying the class through reflection. How can I get back the normal class or is there any other way to convert these objects to XML automatically (I am looking for available packages rather than writing my own code to do the conversion).

Thanks in advance
Phani


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 9:01 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

Do you retrieve your Facility-object from another hibernate-managed object?

When hibernate utilizes lazy-loading it will replace all contained object with proxies that will only be intialized on access during the session, and it seems this is what you're passing to XStream.

If you want to avoid this you could either disable lazy-loading for this property in the mapping-file or you could resolve the proxy manually.
To replace a Proxy for myObject by the real class you could use Hibernate.isInitialized(myObject) to check, if the proxy is already resolved and if it isn't call Hibernate.initialize(myObject) to get the proper object.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 08, 2006 4:28 pm 
Newbie

Joined: Tue Jul 19, 2005 1:28 pm
Posts: 17
Hi,

Thanks a lot. That seems to work. But the problem is if there is tree of objects i.e. collection of objects within Facility and each of the objects in the collection, themselves have other collections, how do I initialize all of them in single go. Looks like I explicitly have to initialize all of collections. Is there any other way apart from enabling disabling lazy initialization?

Thanks
Phani

piet.t wrote:
Hi,

Do you retrieve your Facility-object from another hibernate-managed object?

When hibernate utilizes lazy-loading it will replace all contained object with proxies that will only be intialized on access during the session, and it seems this is what you're passing to XStream.

If you want to avoid this you could either disable lazy-loading for this property in the mapping-file or you could resolve the proxy manually.
To replace a Proxy for myObject by the real class you could use Hibernate.isInitialized(myObject) to check, if the proxy is already resolved and if it isn't call Hibernate.initialize(myObject) to get the proper object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.