-->
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.  [ 13 posts ] 
Author Message
 Post subject: Hibernate and Hessian incompatible?
PostPosted: Fri Jul 09, 2004 11:04 am 
Beginner
Beginner

Joined: Wed Feb 25, 2004 6:23 pm
Posts: 39
Has anyone tried sending a Hibernate persisted object (with a Set) across a Hessian remote call? It appears that Hibernate's collection classes are not compatible with the way Hessian serializes objects, but I can't believe I'm the only who has tried this (I've done some searches and can't find anyone else mentioning the problem). Yes, the Set is initialized, and no, the persisted object is not a proxy.
This is Hibernate 2.1, btw.

Thanks,
Anodos


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 12:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There should not be a problem with initialized sets, I think. But yes, the Hessian Serialisation is definately a problem, because Hibernate does a lot of custom serialisation handling. I already had this problem too already. I ended up using http://switchrmi.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 7:07 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 6:23 pm
Posts: 39
As it turns out, the solution to using Hibernate with Hessian is to not include the hibernate jar with the client application. The reason is because Hessian treats Collections specially: if an object implements any of the Collection interfaces (List, Set, etc), then Hessian will use the collection accessor methods instead of field level introspection to serialize/deserialize the collection. This means that on the client side, Hessian will create a new Hibernate Set instance, for example, and then call its "add" method in a loop. This results in an exception thrown from Hibernate's Set instance. However, if Hessian cannot find the specific collection instance in the classpath, it will revert to using a default collection instance (HashSet as opposed to Hibernate's Set)... this means that on the client side, all your collections will be standard Java collections instead of Hibernate collections (as long as you do not include the Hibernate jar with your client). Hessian will have essentially "scrubbed" Hibernate off of your data objects.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 7:08 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
That is actually nice.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 10, 2004 9:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hm yes, thats nice - it still can't handle uninitialized collections though?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 1:22 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 6:23 pm
Posts: 39
Good question. I don't have any use cases (yet) where I have uninitialized collections by the time I'm serializing them across Hessian. However, since Hessian uses accessor methods (iterators) to deserialize the Collection, then you need to either initialize the collection before sending it across Hessian, or keep your Session open while sending the Collection. The iterator will attempt to initialize the collection, and this will happen on the server side at the point where the collection is serialized via Hessian. Otherwise, I'm sure you'd get a Hibernate exception (on the server side) at the point where the server attempts to transmit the collection.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 7:51 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Not really germane to Hessian, but what the heck: we rolled our own bean serialization on top of XML-RPC (we needed a good, non-RMI way to do service invocations between two apps running on different versions of the JDK, and a little reflection on top of XML-RPC works very well).

For uninitialized collections, our object graph walker just detects the uninitialized state and serializes an empty collection. It also serializes collections generically.

This basically both strips the Hibernate collections from the wire format, and also truncates the object graph at uninitialized lazy collections, which is pretty much exactly what you want.

Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 1:29 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Is there any utility clas that can be used to substitute a hibenate lazy loaded collection for a regular one ?

Ie something that traverses the object graph and initializes everything.

It is cool to have lazy loading by default but even cooler if you could just
turn it off whenever you wanted without the overhead of loading the object
and then having to itterate to make it non lazy.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Iterate through all PersistentClass objects in Configuration, set lazy to false and outer-join to false, rebuild the SessionFactory. This will load any referenced instances into memory whenever you load a single entity.

P.S. This is not what you want to happen usually. You are looking for a solution, but probably should rethink the problem.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 8:20 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Hi all, thought this might be of interest to people who are using
hessian. Apparently it's basically the same as hessian but is
more like rmi and will increase hibernate compatability.


http://forum.springframework.org/viewto ... ht=invoker

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: serialization
PostPosted: Wed Aug 18, 2004 1:23 am 
Newbie

Joined: Wed Aug 18, 2004 1:16 am
Posts: 1
maybe you should use adifferent protocol which uses java serialization.

e.g. the springframework has some support for that:
org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter
this protocol uses http and java serialization.

RMI should also work.


Top
 Profile  
 
 Post subject: Re: Hibernate and Hessian incompatible?
PostPosted: Mon Jan 14, 2013 11:56 am 
Newbie

Joined: Wed Nov 07, 2012 8:28 am
Posts: 1
hey guys,

you made my day!
I also did some prototyping with Spring remoting + Hessian + Hibernate and got stuck with org.hibernate.LazyInitializationException.

The last comment mentioning HttpInvokerServiceExporter did it for me. And it was a simple change of 2 lines in configuration (replacing Hessian).
That is cool!
Thanks.


Top
 Profile  
 
 Post subject: Septorinoplasti
PostPosted: Wed Jan 16, 2013 7:23 am 
Newbie

Joined: Wed Jan 16, 2013 7:21 am
Posts: 3
Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!
------------------------------------
Septorinoplasti


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