Integrating Hibernate with Spring 3 Web MVC

This tutorial on “Integrating Hibernate with Spring 3 Web MVC” incorporates:

  1. Hibernate Transaction Control
  2. @RequestMapping friendly URL’s. More on this specific Spring 3 Web MVC friendly URL topic here. (Alternative @RequestParam method here)
  3. A Generic DAO suitable for Hibernate operations with Spring 3 Web MVC. More here in this separate Generic DAO tutorial.
  4. Spring 3 Web MVC Dependency Injection (DI) and Inversion  of Control (IoC). More on DI and IoC here.
  5. Netbeans (7.1.1 used here but any version will do)

The complete Netbeans project is available for download here. The SQL for the project is included in the download in the WEB-INF folder.

Update: Jan 8, 2014


The project originally available for download does not work with Netbeans 8 due to libraries that were in Netbeans 7.1.1 no longer available in Netbeans 8. Additionally, a comment below referencing Netbeans 7.0 .1 may suggest the same problem. This enforces the point that a dependency management utility is a much better means of building projects. To that end this project has been recreated using Maven. This ensures it will work irrespective of IDE version. In fact because it’s a maven project it’s not dependant on an IDE at all. It should work on any IDE that supports Maven. Netbeans of course, does support Maven. Here is the download link SpringHibernateCrudMvn for the Maven version of this application.

The POM is quite comprehensive in that it includes support for Spring, Spring-Security, Jackson, Hibernate, Hibernate-search and a bunch of other utilities. It can serve as a template to a certain extent.

—————————————————— (/End Update)

Continue reading “Integrating Hibernate with Spring 3 Web MVC”

Annotated Dependency Injection / Inversion of Control (DI / IoC) in Spring 3 Web MVC using Netbeans

This tutorial will detail how to insert services and components (Dependency Injection) into a Spring 3 Web MVC Netbeans application.

The process used is Dependency Injection (DI) or Inverse of Control (IoC) whereby Spring will instantiate (or inject) certain components at runtime rather than at having them initiated at compile time.  This provides a highly decoupled design which facilitates ‘change’ more easily. Importantly, it also makes comprehensive Unit Testing (with Mock Objects) much easier to achieve. IoC is a conventional design pattern.

This tutorial is quite comprehensive in that it will simulate CRUD operations on ‘Person’ objects. For simplicity, it does not used a database, data will be put stored in the ‘HttpSession’ object instead.

The code is available for download at the bottom of this page. Continue reading “Annotated Dependency Injection / Inversion of Control (DI / IoC) in Spring 3 Web MVC using Netbeans”