First off I'm using a struts plugin to load the hibernate session factory and store it in the servlet context. I then have all of the struts actions call a helper class that contains all the business logic (add, edit, delete, find, etc...).
From the struts actions I pass the servlet object to the helper class in order to use hibernate session factory. Is this a good design approach?
This sounds like a good approach. The only thing I could suggest is that it might be better to have a number of classes that handle the persistence for various categories of classes (usually called DAOs, or Data Access Objects), rather than a single helper class.
The March issue of JDJ has an excellent article on how to design POJO applications. The article gives a sample pattern that you might find useful. Here is the URL:
From a theoretical "separation of layers" view, you do not want your business tier to know that it is being used in a web application. You should be able to reuse your business classes to build a client sever application or a web service. Also ideally, your web application would not know that it is using Hibernate as its persistence technology (though in reality, it seems that the persistence technology choice tends to heavily influence the other layers).
I guess my point is that I would not pass the servlet context object into the business tier. I would have some utility method in the presentation tier that would retrieve the "hibernate session factory" and pass that into your helper class.
Joined: Jan 30, 2006
Thanks for the info... I do think that one of my issues was using the struts plugin to create my Hibernate SessionFactory. Do you think that a Singleton would be a better solution???