Migrating to Spring 3.1 and Hibernate 4.1

The application has been updated to Spring 3.2. The new version is available here: Spring 3.2. The old one is still available: Spring 3.1.

As part of the Core-Spring course, we have a lab application that we use to show how to integrate Spring and JPA/Hibernate together. We have just upgraded it to Spring 3.1 / Hibernate 4.1, and thought we should share a few tips.

1) Maven Dependencies

The configuration sample below is based on Maven (but you can easily convert it to Gradle if needed). Inside your POM, you should specify the latest versions of Spring and Hibernate (you might need to declare more Spring dependencies depending on which Spring components you’re using).

3) Do you need that CGLIB dependency?

Adding features such as Transactional behavior, Security, Caching… to a Spring bean that does not implement an interface (more information here)

When the @Transactional annotation is used inside a JUnit Test case (you usually do that so the database transaction can rollback at the end of each test case, see here for more details).

…

4) Java Configuration

Using Java Configuration with Spring is an interesting alternative to xml-based and annotation-based configuration.So how to work with Spring and Hibernate using Java configuration? A new class called LocalSessionFactoryBuilder makes things pretty easy.