-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate PersistentList v/s Java List
PostPosted: Mon Jan 29, 2007 5:55 am 
Newbie

Joined: Mon Jan 29, 2007 5:48 am
Posts: 1
Hi,
I am persisting a class containing a member variable whose type is List<user defined object>. When I try to retrieve the persisted instance of this class, the List object is replaced by a PersistentList, which is a hibernate class.

My application is such that the persistence is done at a layer other than the client, and therefore the inclusion of this PersistentList makes it mandatory for me to include the hibernate.jar file in the client, which I do not want.

Is there any way of handling this ?

Regards,
Sudipto


Top
 Profile  
 
 Post subject: Re: Hibernate PersistentList v/s Java List
PostPosted: Mon Jan 29, 2007 3:16 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
May be I do not understand...
How does your persistent class get from the Java VM using Hibernate and thus hibernate.jar to the 'other layer' (client)?
Is that one (client) running in a different Java VM (different class loader / class path)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 8:36 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Hibernate uses Persistent[Collection] to handle lazy-loading. I think the only solution you have is to disconnect object that you're going to send to the client side and then addAll() on a new Java List to you will reset at the old place.

Yes, I know, it seems quite complicated. But I'm not sure there's another way. I don't remember if Hibernate can avoid using PersistentList, maybe when using StatelessSession?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 11:22 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
What behavior were you hoping to preserve by persisting this class in this way? If you don't care about tracking the dirty objects and whatnot, and only that the collection of objects remains the same for save.load, then you can write your own writeObject method. When you do, just copy your list into an ArrayList before you save.

There is also another more complex way using annotations which is basically the system RMI uses.

But overall might I suggest that you keep the layer responsible for the creation of an object also responsible for its storage and loading. I overcame this project in my application by handing out tokens to my objects and keeping my objects from crossing classloader boundaries. Well at least I do not allow saving in the classloader that did not create the object.


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