Hibernate Remote Lazy Loading to the Rescue

I’ve written a couple of posts recently on Lazy Loading, and some of the issues relating to how Hibernate creates and manages proxies.  While lazy loading itself is meant to improve performance, it can still lead to exceptions caused by objects being detached from their session.  As a web service becomes more distributed, and the number of requests increases the need for lazy loading remotely becomes more important, but implementing it without unintended consequences can

Posted at 9am on 06/16/09 | no comments | Filed Under: Coding & Debugging read on

Class Cast Exception is a Proxy Problem - Revisited using the Visitor Pattern

In my previous post: ClassCastException is a Proxy Problem I talked about how Hibernate tries to optimize the loading of objects by lazily fetching the parent class object, and returning a proxy for the subclass instead of the actual subclass, thus causing a ClassCastException when the proxy is cast to the actual subclass.  The proxied object doesn’t contain member variables or a representation of the subclass’ methods, only the parent’s.

My proposed solution to the ClassCastException was to add

Posted at 9pm on 06/13/09 | no comments | Filed Under: Coding & Debugging read on