0% found this document useful (0 votes)
9 views

Hibernate&struts 2

This Java class file defines a HibernateUtil singleton class that is responsible for creating and managing Hibernate sessions. It initializes a SessionFactory from a configuration file and provides a getSession() method to return an open session with an active transaction for performing database operations. The getInstance() method ensures only one instance of the class is created.

Uploaded by

Fabiano Farah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Hibernate&struts 2

This Java class file defines a HibernateUtil singleton class that is responsible for creating and managing Hibernate sessions. It initializes a SessionFactory from a configuration file and provides a getSession() method to return an open session with an active transaction for performing database operations. The getInstance() method ensures only one instance of the class is created.

Uploaded by

Fabiano Farah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

HibernateUtil.

java

package br.hibernate.dao;

import org.hibernate.Session;

public class HibernateUtil {

private SessionFactory sessionFactory;


private static HibernateUtil me;

private HibernateUtil(){

sessionFactory = new
AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();

}
public Session getSession(){

Session session = sessionFactory.openSession();


session.beginTransaction();

return session;

public static HibernateUtil getInstance(){


if(me==null){

me= new HibernateUtil();


}
return me;
}
}

Page 1

You might also like