June 18, 2019

Hibernate and Struts base configuration

Hibernate is a powerfull Object Relationl Mapping java-based framework. It consists of a collection of related projects enabling developers to utilize POJO-style domain models in their applications in ways extending well beyond Object/Relational. In this article I will create a Hibernate ORM base configuration for a Struts MVC web application. Suppose you have already created a web dynamic java project using the Eclipse IDE (take a look here). For this example I will use a Mysql database connector driver.
Let’s see now the main steps to configure hibernate in a java struts web project.

SOURCE CODE (/giuseu/struts-mvc)

git clone https://gitlab.com/giuseppeurso-eu/struts-mvc


Create a database sample schema:

 STEP 2.

Download and unzip the Hibernate 3.3.2 release bundle:  http://sourceforge.net/projects/hibernate/files/hibernate3/



Copy the following jar libraries into the project WebContent/WEB-INF/lib directory:

 STEP 4.

Download the Mysql JDBC Driver and copy the jar file in the lib directory project: http://dev.mysql.com/downloads/connector/j/


Create the hibernate.cfg.xml hibernate configuration file in the “src” project directory:

 STEP 6.

Create a utility class to build the hibernate SessionFactory from hibernate.cfg.xml

 STEP 7.

Create a servlet filter to check the hibernate SessionFactory

 STEP 8.

Declare the servlet filter in the web.xml file:

The final project layout should look like this


 STEP 9.

Start Tomcat in Eclipse, if not errors occur you can see the following INFO messages:


Related posts

Leave a Reply

Your email address will not be published.