Two Laptop Bag*
The moose likes Struts and the fly likes design question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "design question?" Watch "design question?" New topic
Author

design question?

alan wamser
Ranch Hand

Joined: Jan 30, 2006
Posts: 41
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?

Alan
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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:

http://jdj.sys-con.com/read/180374.htm


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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.

- Brent
alan wamser
Ranch Hand

Joined: Jan 30, 2006
Posts: 41
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???
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: design question?
 
Similar Threads
Hibernate/Struts question
designing hibernate apps
Struts-hibernate Integration
Thread safety and servlets
Keep Hibernate session with Struts