Ilja wrote:
I'm still deciding whether to go for Spring or Struts, but are there any downloadable examples which give a good example on how to incorporate Hibernate in a layered artichecture?
As outlined in the article in the Hibernate community area (
http://www.hibernate.org/110.html), Spring offers a lot of features for setting up business and data access objects. From wiring up in an IoC style to declarative transaction demarcation, there should be everything you need for a proper and convenient local (non-remote) middle tier. This will work with all sorts of transaction and data access strategies, and with any client layer - be it Spring web MVC, Struts, WebWork, or a Swing UI.
Struts on the other hand is "just" a web MVC framework, like WebWork. That is fine, of course, but does not compete with Spring's middle tier features. Spring's web MVC is one of Spring's features, but by no means central: Use it if you like to, use any other web MVC framework if you prefer. Spring is as a la carte as possible: In contrast to other application frameworks like Expresso, it explicitly supports selective usage of features and seamless integration with other solutions.
So Spring vs Struts is not an exclusive choice: Spring web MVC vs Struts is. We have numerous users that combine a Struts web layer with a Spring business layer, mainly because of existing investments in Struts. Basically, you access Spring-configured business beans from within your Struts actions in such a scenario. See the "Web MVC" article on the Spring website (
http://www.springframework.org/docs/web_mvc.html) for details, especially the section talking about integration.
A transaction strategy for Hibernate and support classes for IoC-style Hibernate access code make implementing Hibernate-based DAOs as simple as possible. Unfortunately, there is no full-fledged sample app for Spring/Hibernate yet: I'm currently working on one, though. The existing "webapp-hibernate" skeleton included in the Spring distribution should be a start for a typical application context configuration, illustrating both the business layer and a web layer on top.
Your Hibernate DAOs just implement the actual data access logic, preferably via HibernateTemplate, without dealing with transaction demarcation or explicit Session creation. Business objects demarcate transactions and invoke methods of DAOs (see the article). If you've got any specific questions regarding the implementation of such DAOs, let me know: I'm involved in 3 commercial products based on Spring/Hibernate, so I should be able help.
Juergen