Struts2.2.1 and hibernate integration application
Posted on: March 4, 2011 at 12:00 AM
In this application, you will see how to integrate struts2.2.1 and hibernate.

Struts2.2.1 and hibernate integration application


The HibernateUtil is a java class which provides SessionFactory from the Hibernate configuration file.  It manages the Hibernate session. HibernateUtil class is a helper class that handle Hibernate's SessionFactory to obtain a Session object. This class load the hibernate.cfg.xml file using configure() method.


package net.roseindia.hibernateUtil;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new AnnotationConfiguration().configure()
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);

public static SessionFactory getSessionFactory() {
return sessionFactory;

Related Tags for Struts2.2.1 and hibernate integration application: