All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.caelum.stella.hibernate.example.util.HibernateUtil Maven / Gradle / Ivy

There is a newer version: 2.1.6
Show newest version
package br.com.caelum.stella.hibernate.example.util;

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

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy