1

I'd like to add Hibernate Objects to an HTTP Session. Where the HTTP Session is participating in a clustered environment and is replicated through serialization. While serializing the HTTP Session, a lazy loading exception is thrown because it is outside the scope of a session. It seems like there should be a way to instruct hibernate to not attempt to serialize an object that hasn't been lazy loaded. After all, that is the state of the object graph and serialization dumps the state of the object graph. If an object is merely a proxy because it hasn't been loaded then only the proxy should be serialized. Right? Anyway, that's the behavior I'm hoping to see. Any ideas on how to make this happen?

Of course the expectation is the serialized object could be deserialized on another server and the session would be processed appropriately.

1 Answer 1

2

In cluster environment you might want to store only objectIds in the HTTP session. So that the cluster node will be able to query the DB for the real node.

Another option is to detach the Hibernate Object from the Hibernate Session and serialize it. (In this case you may need to initialize the lazy fields).In order to initialize the lazy-loaded fields you might want to use this

Generally, if you're passing objects between servers you must initialize all lazy loaded fields, or you will get an exception while serializing, because you will not be able to serialize / deserialize the hibernate Session.

And yeah, do not mix HTTP sessions with Hibernate Session. These are completely different things.

Sign up to request clarification or add additional context in comments.

3 Comments

Funtik, Thanks for the response! This involves a legacy application putting Hibernate objects in the HTTP Session. This worked fine until it was deployed to a clustered environment and serialization was used to replicate the state. Refactor to store just the object ids would be quite an undertaking. I was hoping to find a solution where Hibernate would avoid serializing non-loaded objects.
try detaching the objects from hibernate session before adding it to HTTP session
Funti, Another excellent suggest, but sadly in my case this is doable. The application uses Tapestry, which adds certain class attributes to the session under the covers. As such, I don't have visibility to point at which the Hibernate objects are added to the session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.