Partial loading of POJO with Hibernate is a current usage to prevent loading of unnecessary data. The persistence library deals with these unloaded associations by handling proxies.
So you cannot send a partially loaded Hibernate POJO to the GWT client side.
The general solution: Data Transfer Object and Dozer
Depending on the Hibernate session state (open or closed), Dozer will load the entire POJO association graph or raise a LazyIntialisationException. Indeed, by default Dozer tries to clone all properties: if the session is opened, they are lazy loaded, otherwise Hibernate throws an exception.
Well, the workaround mostly used is to define clone configuration with Dozer that only copy the loaded associations:
This solution works, but it poses some issues:
The clone POJO can be manipulated by the GWT layer painlessly.
For update, the clone POJO must be merged with an existing Hibernate one to prevent lazy associations to be replaced by null (which would lead Hibernate to delete the association instead of leaving it unchanged).
The hibernate4gwt can store and restore seamlessly the Hibernate POJO in the HTTP session (stateful mode) or load a fresh new Hibernate Pojo before merge (stateless mode).
Copyright 2007. All Rights Reserved