import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
/**
* @author premkumar.bharti HibernateUtil creates sessions for daolayer
*/
@SuppressWarnings("all")
public final class HibernateUtil {
private static SessionFactory sessionFactory = null;
/**
* creates a session with the database.
*
* @return session factory object.
*/
@SuppressWarnings("deprecation")
private static SessionFactory buildSessionFactory() {
if (sessionFactory == null) {
try {
if (sessionFactory == null) {
sessionFactory = new AnnotationConfiguration().configure()
.buildSessionFactory();
} else {
return sessionFactory;
}
} catch (Exception ex) {
throw new ExceptionInInitializerError(ex);
}
}
return sessionFactory;
}
/**
* return SessionFactory to get new Session out of it
*
* @return SessionFactory
*/
public static SessionFactory getSessionFactory() {
return buildSessionFactory();
}
private HibernateUtil() {
}
}
No comments:
Post a Comment