Third attempt at posting - the session time out must be low, or I'm typing really slow tonight.
I've actually given up using the OpenSessionInView pattern.
I now consider the level of hydration of the object graph as part of the buisness logic and so write services that explicitly set this level. In this manner consumers of the services know what they are getting, and conceptually there is no difference between different methods of consuming or publishing the services. I've found this is the simplist solution, and one that avoids potential hidden lazy initialization errors from biting you.
dorel wrote:
My question was not really about synchronization but about how can you make sure you have a session opened when fetching a lazy collection in a desktop app w/o using one single session opened for the entire lifetime of the application.
In a web app you have OpenSessionInViewFilter, I imagine one can do the same thing in a desktop app but then you should "simulate" how the server works, meaning a new thread for each action involving hibernate and for each new thread, a Session bounded in a ThreadLocal.
Thanks.