码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate4 下的hibernateUtil

时间:2014-12-22 14:18:53      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil
{
    private static final SessionFactory sessionFactory;
    static
    {
        try
        {
            Configuration cfg = new Configuration().configure();
            ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();

            sessionFactory = cfg.buildSessionFactory(serviceRegistry);
        }
        catch (Throwable e)
        {
            throw new ExceptionInInitializerError(e);
        }
    }

    private HibernateUtil()
    {
    }

    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }

}

Hibernate4 下的hibernateUtil

标签:

原文地址:http://www.cnblogs.com/satcup/p/4177928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!