-->
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: Serialization and Hibernate custom collection types
PostPosted: Sat Feb 25, 2006 6:58 am 
Newbie

Joined: Sat Feb 25, 2006 6:46 am
Posts: 9
Hello.

I've looked at the past topics, but i have not found a real anwser... I'm sure someone has a smart solution !

A server application, in a J2EE EAR, uses Hibernate to read and write objects to and from a database. The object model presents different cases of associations. All that works as expected within the application.

The object model must be shared with other applications, like a J2EE application client executed out of the application server. This client must be as thin as possible, and can't import Hibernate.

I've tested several cases, changing relationship mapping not to be lazy, or forcing dependances initialization using the Hibernate.initialize, but no way to make it work : the Set type is always the Hibernate one, and, obviously, my client always fails to deserialize it !

So, now, the questions...

Can i really share the object model with other applications that don't use Hibernate, or should i duplicate the full model to have a separate with no Hibernate dependances ?

If yes, what is the solution to serialize an object graph relationships backed by Hibernate collection types, and deserialize it with no Hibernate dependances in the client context ?

Thanks for your help.

--
Ephemeris Lappis


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 7:35 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
You can implements Extrernalizable in all classes having associations. In writeExternal(), write yourself sets, lists etc. yourself and then in readExternal() read them yourself.

For instance to write a list or a set, instead of :

Code:
out.writeObject(members);


Do :

Code:
out.writeInt(members.size();
for (Object member: members) {
  out.writeObject(member);
}


And to read it :

Code:
int size = in.readInt();
members = new ArrayList(size);
for (int i=0; i<size; i++) {
  members.add(in.readObject();
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 8:02 am 
Newbie

Joined: Sat Feb 25, 2006 6:46 am
Posts: 9
You're right ! This is a solution. But it seems a bit tedious to change the serialiation for all objects.

I'd hoped a solution exists in Hibernate to change this form an external point of view. I'm sure many people has experienced the same problem with distributed applications...

Thanks anyway.

--
Ephemeris Lappis


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.