Home Struts Struts Struts2.2.1 Integration Struts2.2.1 and hibernate integration application

Ask Questions?

View Latest Questions


 
 

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

Struts2.2.1 and hibernate integration application


HibernateUtil.java

Description

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.

Code

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()
.buildSessionFactory();
} 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:


DMCA.com