Spring integration with hibernate

Almost similar to what we have done in our previous article on a login application in Spring using JDBC template. To demonstrate the Spring integration with Hibernate, we will instead be using HibernateTemplate.

Quickly moving ahead with the application, lets configure the web.xml first


Location: /WebContent/WEB-INF/

Next, let’s configure the dispatcher-servlet.xml


Location: /WebContent/WEB-INF/


Location: /src/

Make sure you have the proper property file entries as:

These are the key values used in datasource configuration in dispatcher-servlet.xml file.

The views i.e. index.jsp, login.jsp and welcome.jsp remains the same as for our previous application. Click here for instant navigation

Now let’s start with creating the Java classes. We would prefer going for the bean first i.e. UserBean.java inside the package com.jCombat.bean.

Create the DAO interface as ICombatDAO.java in package com.jCombat.dao as:

Create the DAO class as CombatDAO.java in the package com.jCombat.dao

Create service interface as ICombatService.java in package com.jCombat.service, as:

Create service class as CombatService.java in package com.jCombat.service, as:

Finally let’s create the controller class as CombatController.java in package com.jCombat.controller as:

This was all, but do make sure that the following points have been taken care of to avoid unexpected errors:

  1. Make sure you have created table “userbean” in the database with two columns “userid” and “password” of type varchar2 and provide some values in it.
  2. Before executing this project, do make sure the database engine is running otherwise you will get connection errors.

Now you can execute your project by right-clicking your project in Eclipse and choose Run as->Run on server

I hope this post was fair enough. Do comment for your queries and feedback on the same.

Download the source code here

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.