Here’s a long article to show you how to integrate JSF 2.0Spring and Hibernate together. At the end of the article, you will create a page which display a list of the existing customer from database and a “add customer” function to allow user to add a new customer into database.
P.S In this example, we are using MySQL database and deploy to Tomcat 6 web container.

1. Project Structure

Directory structure of this example
jsf2-spring-hibernate-folder-1
jsf2-spring-hibernate-folder-2

2. Table Script

Create a customer table and insert 2 dummy records.
DROP TABLE IF EXISTS `mkyongdb`.`customer`;
CREATE TABLE  `mkyongdb`.`customer` (
  `CUSTOMER_ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `NAME` VARCHAR(45) NOT NULL,
  `ADDRESS` VARCHAR(255) NOT NULL,
  `CREATED_DATE` datetime NOT NULL,
  PRIMARY KEY (`CUSTOMER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
 
INSERT INTO mkyongdb.customer(customer_id, name, address, created_date)
VALUES(1, 'mkyong1', 'address1', now());
INSERT INTO mkyongdb.customer(customer_id, name, address, created_date)
VALUES(2, 'mkyong2', 'address2', now());

3. Hibernate Stuff

A model class and Hibernate mapping file for customer table.
File : Customer.java
package com.mkyong.customer.model;
 
import java.util.Date;
 
public class Customer{
 
 public long customerId;
 public String name;
 public String address;
 public Date createdDate;
 
 //getter and setter methods
 
}
File : Customer.hbm.xml
 version="1.0"?>

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

     name="com.mkyong.customer.model.Customer" 
        table="customer" catalog="mkyongdb">
 
         name="customerId" type="long">
             name="CUSTOMER_ID" />
             class="identity" />