JSF 2 + Hibernate 4 Integration Example Using Gradle

By Arvind Rai, January 24, 2015

This page will provide the example of JSF 2 and hibernate 4 Integration. To do this create hibernate utility to get hibernate session. And create Dao to fetch and save data in database. Now call the Dao method in JSF 2 managed bean to use hibernate. In our example, we are using a user form to save in MySQL database with tomcat server.

Software Required to Run Example

To run the example, we need the below software.

1. Java 7
2. Eclipse
3. MySQL
4. Tomcat
5. Gradle

Project Structure in Eclipse

Find the project structure in eclipse of demo application.

Create Hibernate Utility using StandardServiceRegistryBuilder

To integrate hibernate and JSF, we have to create a hibernate util. In hibernate 4, we build the session using StandardServiceRegistryBuilder.
HibernateUtil.java