The original tutorial can be found at: Using Hibernate in a Web Application. This is a refined version with details steps.
In this tutorial, you use the NetBeans IDE to create and deploy a web application that displays data from a database. The web application uses the Hibernate framework as the persistence layer for retrieving and storing plain old Java objects (POJOs) to a relational database.
Hibernate is framework that provides tools for object relational mapping (ORM). The tutorial demonstrates how to add support for the Hibernate framework to the IDE and create the necessary Hibernate files. After creating the Java objects and configuring the application to use Hibernate, you create a JSF managed bean and JSF 2.0 pages to display the data. Before starting this tutorial you may want to familiarize yourself with the following documents.
Hibernate documentation at hibernate.org (http://hibernate.org/).
Note. This tutorial uses NetBeans IDE 6.8. If you are using NetBeans IDE 6.7, please see Using Hibernate in a Web Application in NetBeans IDE 6.7. If you are using NetBeans IDE 6.5, please see Using Hibernate in a Web Application in NetBeans IDE 6.5.
Contents
Creating the Database
Creating the Web Application Project
Modifying the Hibernate Configuration File
Creating the HibernateUtil.java Helper File
Generating Hibernate Mapping Files and Java Classes
Creating the FilmHelper.java Helper Class
Creating the JSF Managed Bean
Creating the Web Pages
Running the Project
Downloading a Complete Project
To follow this tutorial, you need the following software and resources.
Software or Resource |
Version Required |
NetBeans IDE |
6.8, Java version |
Version 6 |
|
Sun GlassFish Enterprise Server |
v3 |
Version 5.x |
|
Sakila Database |
Plugin available from update center |
Notes:
GlassFish v3 requires Java Development Kit (JDK) 6.
If you are using GlassFish v2 or an older version of NetBeans IDE, see Using Hibernate in a Web Application - NetBeans IDE 6.7 Tutorial.
Creating the Database
This tutorial uses a MySQL database called sakila, a free sample MySQL database that is available from the MySQL site. The sakila database is not included when you install the IDE so you need to first create the database to follow this tutorial.
To create the sakila database you can download and install the Sakila Sample Database plugin using the Plugins manager. After you install the plugin the sakila database is added to the list of databases in the Create MySQL database dialog box.
1. Open the Plugins manager and install the Sakila Sample Database plugin.
------------------------------------------------------------------------
------------------------------------------------------------------------
2. After installing the plugin, start the MySQL database by expanding the Databases node in the Services window, right-clicking the MySQL Server node and choosing Start.
3. Right-click the MySQL Server node and choose Create Database.
4. Select the Sakila database from the New Database Name drop down list in the Create MySQL Database dialog box. Click OK.
When you click OK a Sakila node appears under the MySQL Server node. If you have been asked to create tables for the already available Sakila sample database, then click Yes.
5. Right-click the Sakila node and choose Connect.
When you click Connect a database connection node for the Sakila database (jdbc:mysql://localhost:3306/sakila [username on Default]) is listed under the Databases node. When a connection is open you can view the data in the database by expanding the connection node.
The bold database name means it is connected as shown in the following screenshot for sakila database.
Back to Main | Java, ORM & Hibernate 2