What do people think about this:
I would like to be able to load a domain object, pass it to the view, and enable the view to traverse the domain object graph without any knowledge of the persistence machanism (Hibernate).
In web applications, the "Open Session in View" is an option, but this option doesn't apply for a standalone application with a Swing/SWT GUI.
Another option is to use around advice, with a pointcut that catches calls to domain accessor methods. The advice would attempt to proceed with the method, if the method throws a LazyInitializationException, a new Hibernate Session would be obtained, the domain object on which the accessor method is being invoked would be reattached to the new Session, and the method would be attempted again, and should succeed. Of course, the domain object has no knowledge of the persistence of its collaborators:
domainObject1.getDomainObject2();
This should work nicely, as someone has indicated here:
http://www.jroller.com/page/cenkcivici?entry=reattaching_lazy_objects_to_hibernate
The only problem, as noted at the same URL, is that the constructor for LazyHibernateException logs an error message. Two JIRA issues to have this log statement removed have been turned down: HHH-2025, HB-1363.
So what do people think? Is this a legitimate use of LazyInitializationException / Hibernate Session? Is this reason enough to remove the log statement in the LazyInitializationException constructor?
Cheers
Russell