Question

I need a quick jump start for using Spring and Hibernate together and I was looking for some sample code to modify and extend. Bonus points for Struts2 and Spring Security integration.

Was it helpful?

Solution 3

There is a sample project that includes Spring, Hibernate and Struts2 available from the Struts2 website that appears to have most of what I want. It includes a basic JPA configuration but it does not provide DAO classes.

The generic DAO pattern is documented on the Hibernate site here. This gives a good DAO foundation but the code is using Hibernate directly with no JPA or Spring.

The following post (warning: language) gives some information about using Spring with JPA and not the HibernateTemplate class.

Put together this information has me well on the way to my skeleton project.

OTHER TIPS

The official docs is your best bet for both Spring and Hibernate. However, you can look into When Spring Meets Hibernate and Spring and Hibernate with MyEclipse tutorial to get you started.

Your best bet, if you are using Netbeans or have no problems in using that, just start a brand new application and follow the web application wizard and specify Spring and Hibernate as application framework, and ORM respectively. It will generate a complete skeleton for you to work on. You can even add Struts2 as web framework later, in project->properties->framework.

You might want to look into Struts2 Spring Plugin for the latter. Further, Spring Security Integration.

Have a look at AppFuse

It has lot of starter web-app material. You also have something with Struts2-Spring-Hibernate.

SpringSource itself have a good number of good sample applications available here:

https://src.springframework.org/svn/spring-samples/

The best one to get started with here is probably:

http://static.springsource.org/docs/petclinic.html

Spring Roo creates a Spring - Hibernate skeleton with JPA 2. You can continue using Roo or you can switch it off with not much manual work. It downloads the newest Hibernate and Spring versions and you can be sure they will work together.

Spring Roo gives you advice with the "hint" command and you can start really quickly. You can follow the tutorial at http://static.springsource.org/spring-roo/reference/html/beginning.html and the first two steps are enough.

But Roo will not help with Struts, it offers JSF instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top