Integrating Struts and Hibernate
This article explains the integration of Struts
and Hibernate, two worldwide-accepted
frameworks in the landscape of development
of enterprise applications. Completing this article
will make you able to use Hibernate in your
Struts project. We will be using Hibernate Struts
plug-in to write high performance application
using Struts and Hibernate.
Hibernate is Object-Oriented mapping tool that
maps the object view of data into relational
database and provides efficient persistence
services such as create, read, update and delete
In this article we will implement small search
engine application that shows a search form to
the user. User enters search string and presses
search button. Struts framework processes the
request and passes it to the action for further
processing. Action class uses Hibernate to make
database calls and retrieves matching records
from database and results are displayed to the
Full code for the application is provided with
the article and you can download the zip file
from any link at the bottom of every page of
the article and start working on it for your
project or to learn Struts and Hibernate
Integration. Understanding the application has
been divided in 6 sections as below.
1. Setting up MySQL Database and
This section describes how to setup
database and populate it with the data.
We are using MySQL Database for this
2. Downloading Struts, Hibernate and
This section explains you to setup the
develop workbench for the application.
3. Writing Hibernate configuration file,
POJO class and Tutorial.hbm.xml
(Hibernate mapping class)
In this section, we will write required
hibernate objects like configuration files
and then integrate all the stuffs.
4. Developing Hibernate Struts Plugin
In this section, we will write Hibernate
Struts Plugin Java code and integrate it
with the Struts.
5. Writing Web Client to Search the database using Struts Hibernate
In this section, we will write web client to
test struts Plugin. We will be developing
a search form to search the tutorials
from the table.
6. Build and testing the application
In this section, we will build our Struts
Application and then
1. Setting up MySQL Database and Tables
We are assuming that you have running
instance of MySQL Database and you know
how to work with the MySQL database. To
access the database you should have valid
user name and password.
Let’s now start by creating the database for
our struts- hibernate integration article. Our
application is very very simple and it searches
for the keywords typed by user in the table.
The database will contain one table ‘tutorials’
for holding the tutorials links and
descriptions. Here is the complete sql script
for setting up the database.
CREATE DATABASE ‘struts-hibernate‘ ;
CREATE TABLE ‘tutorials‘ (
‘id‘ INT NOT NULL AUTO_INCREMENT ,
‘shortdesc‘ VARCHAR( 50 ) NOT NULL ,
‘longdesc‘ VARCHAR( 250 ) NOT NULL ,
‘pageurl‘ VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( ‘id‘ )
) TYPE = MYISAM ;
The detail of each of the fields of the table
above is given below:
2007 | Java Jazz Up | 51
|View All Topics
|All Pages of this Issue