steve wrote:
Really the DAOs should not even be opening the hibernate sessions themselves. Typically this should be a higher-level function; the DAOs then just look up the session from a "well known place". Think about two DAOs needing to interact within the same logical unit-of-work...
A nice strategy for this is to use proxies for wrapping the things coordinating access to the DAOs. The proxy would handle things like session and transaction management.
Ok so let me summarize what I've understood so far:
1. CMT Environments - Get the session via the factory.getCurrentSession() method (i.e. let JTA manage things and demarcate the transaction boundaries).
2. Standalone Environments - Use a HibernateUtil/ThreadLocal pattern to externally store the current session in a "well known" place, and have your DAOs retrieve the current session from there or alternately a proxy. This insulates you from the very likely scenario of the "unit of work" not being complete in any particular DAO method.
3. For an application that requires a standalone server in addition to a application server component, you need two DAO implementations: one for the standalone server (implemented ala #2) and one for the application server (implemented ala #1).
Do I have all this right? :) Also, could you point me to any place where I can RTFM on this proxy you speak of?
Thanks in Advance,
Richard...
P.S. As usual you guys have been of great help, thanks for all your comments!