Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

design question?

 
alan wamser
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic