I have to admit it. I had the worst time with Hibernate when I first started learning it a few years ago.  Although I could see the power, the configuration inside Spring was a bit of a nightmare back then.

Today, both Spring and Hibernate support annotation-based configuration, which makes the whole process easier.  Combine this with Hibernate’s Auto-DDL ability (that is, automatic table creation), and it is quite simple to use Hibernate with Spring as long as you follow a few conventions.

The purpose of this article is to build a Hibernate managed Spring web application.  Here are the primary goals:

  • No SQL scripts, not even table creation scripts
  • Minimum XML configuration
  • Relationships defined by Java Persistence API (JPA) annotations
  • Read, write and edit two related classes
  • Make the framework extensible for adding other classes with minimal work

Full source code for this tutorial is available here.

UPDATE March 2014: This code is also available in GitHub at https://github.com/technologicaloddity/departments

Interested? Read on…

Read More