-->
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: LazyInitializationException during serialization
PostPosted: Thu Mar 28, 2013 10:20 am 
Newbie

Joined: Thu Mar 28, 2013 10:01 am
Posts: 2
Hello,
I'm working on an application that puts a lot of Hibernate objects into the HTTPSession. My task is to rework the application to work properly in a clustered environment. This involves replicating the HTTPSession to all servers in the cluster, providing failover capability. That is, if the session is started on one server, and that server goes down, another server can pick up the processing of the session because the HTTPSession has been replicated.

Accomplishing the HTTPSession replication involves serializing the attributes within the HTTPSession. This is done at the end of the request filter chain, which is outside of a hibernate session, causing the LazyInitializationException. There are solutions, such as the OpenViewInSession, that provides a means to operate within a hibernate session for the entirety of the filter chain. But this solution isn't the right fit for the problem at hand. Due to the fact that the object graph could get quit large if all the data needs to be loaded.

The ideal solution would be for the state of the object graph to be serialized as is. Meaning, if an object has not been loaded, then the serialized state should reflect this. When the object graph is deserialized, it should take the form of the original object graph where certain object references haven't been loaded.

Is there a way to instruct Hibernate to serialize as is? That is, don't load a reference if it hasn't been loaded, just serialize a proxy object indicating the true state at the time of serialization. Then if that object is referenced after deserialization, it would be loaded.

It seems this would be a common need. Maybe I'm missing something fundamental. My research has come up with solutions suggesting to create a lot of custom classes that allow the serialization of proxy classes. And then when the object is reference perform a remote call to the originating server to load the data. In this scenario, the remote server down, which is why the session failed over.

The other prevalent solution suggests creating a parallel DTO for each Entity. Essentially a duplicate of the data that serializes only the ID of the referenced object, and defines the reference to the true object as transient. A workable solution, it just seems like it's duplication of code to get around a Hibernate short coming.

Best,
Steve


Top
 Profile  
 
 Post subject: Re: LazyInitializationException during serialization
PostPosted: Tue Apr 02, 2013 10:43 am 
Newbie

Joined: Thu Mar 28, 2013 10:01 am
Posts: 2
Bump...


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.