JavaServer Faces: The Complete Reference

Chapter 9 - The "Virtual Trainer" Hibernate Persisted Implementation Setup Details

Here are the steps needed for configuring and installing the Hibernate persisted version of the Virtual Trainer example application.

Intro

The Hibernate version of the Virtual Trainer application differs from the pure Java prototype in that it actually persists data in a database using Hibernate technology. The application is essentially the same as the Java version, with the exception of the registry classes (TrainingEventRegistry and UserRegistry). In this version, there are the classes TrainingEventRegistryHibernate and UserRegistryHibernate which implement the same interface as the Java versions, except they instead operate with a Hibernate runtime in order to persist data with a database.

Prerequisites Steps

Steps Needed before successfully building and deploying app.

1. You must download the Hibernate 3 "Core" package. The Hibernate download page is: http://www.hibernate.org/6.html

After downloading and unzipping into a local directory (Hibernate_Home). You will see the runtime Jar files in <Hibernate_Home>/redist-lib. The paths to these jars will be specified later in the persistence.properties file.

2. You must have JDBC drivers for you database. As an example, the provided persistence.properties file is preloaded with an example of MySQL and Oracle JDBC driver Jar files. You will have to edit these accordingly.

3. Ant must be installed. (This sample was built with version 1.6.5)

 

Configuration Steps

1. Edit persistence.properties.
After unzipping the virtualtrainerhb.zip, you must edit persistence.properties as per your database and Hibernate jar file locations. The sample persistence.properties provided contains references for MySQL or Oracle databases. Edit as needed - essentially you need to provide the paths to your JDBC jar files and your Hibernate jar files.

2. Edit the appropriate build.*****.xml file.
Edit the appropriate build.*****.xml (if needed) per your database to reference the appropriate persistence properties (defined in persistence.properties). Then rename build.*****.xml to "build.xml".

3. Run the appropriate SQL script trainer*****.sql to install database entities.
Database specific SQL scripts are located at: src/trainer*****.sql and are provided for you to install the Virtual Trainer database entities. Example versions for MySQL and Oracle are provided. Use as appropriate or edit to work with other database type. (Script refers to user/password hbtrainer/hbtrainer).

4. Edit src/hibernate.cfg.xml for your environment.
This is the main Hibernate configuration file. You must specify the following properties based on your database:

<property name="hibernate.connection.driver_class"><Your database driver></property>
<property name="hibernate.connection.url"><Your JDBC connection URL></property>
<property name="hibernate.connection.username"><Your db userid></property>
<property name="hibernate.connection.password"><Your db password></property>
<property name="dialect"><Your DB's SQL dialect></property>

The provided Hibernate config file contains both MySQL and Oracle example configurations. Uncomment and edit as appropriate.

5. Run Ant.
Once your Hibernate and JDBC jar files are properly configured in persistence.properties and build.xml and you've installed your database entities and configured your src/hibernate.cfg.xml file, you may run Ant to build your Webapp!

In the same directory as build.xml, enter "ant" at the command line. This will generate a virtualtrainerhb.war file in the build subdirectory. You can then deploy the War file to any J2EE container such as Tomcat.

Note: To clean out the build subdirectory, enter "ant clean".

Return to Chapter 9 details page

Return to download page


Contact Information | For general questions: jsfcomprefinfo | For errata: jsfcompreferrata