Session facade is quite useful, especially if you expect to need to cluster your servers or provide access from one application into another through something other than the database itself. In our case, we are planning to use a Session Facade to present a remote interface to the model portion of an application that other applications will need access to. The facade will also provide business rule validation and encapsulate our business logic. In that manner, the design is actually very similar to the
Quote:
Servlet ---> App ---> Hibernate ---> DB
approach, although ours will look more like this:
(Struts) ActionServlet --->Action--(RMI)-->SessionFacade--->Hibernate--->DB
In addition, through EJBs, your container can provide some level of automatic transaction demarcation and management.
But scottwilson is correct, EJBs are not without their complications. One of the biggest problems I see is that since our domain objects need to be passed to the client across a remote layer (RMI), they have to be serializable. The lazy-loading proxies hibernate uses (as with any lazy-loading proxy) are not serializable. So in effect, we cannot directly use lazy loading. Instead, we have to either use eager loading (which with the rich relationships in our database could lead to loading huge object graphs to retrieve only a handful of properties), or implement some sort of customizable copying strategy which will copy an object graph at a specified depth. As far as this is concerned, I don't yet have a good plan. I'm hoping
Hibernate in Action will give me an idea of how to handle the problem.