Magazine
 
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 (CRUD).

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
user.

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 table
This section describes how to setup database and populate it with the data. We are using MySQL Database for this application.

2. Downloading Struts, Hibernate and Integrate It
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 Plugine
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 Hibernate Plugin
Application and then test.

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:

 

 
Dec 2007 | Java Jazz Up | 51
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF