Hibernate4工具类的封装

来源:互联网 发布:斗米兼职 知乎 编辑:程序博客网 时间:2024/05/21 11:01
package com.luo.utils;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class HibernateUtil {

private static SessionFactory sessionFactory;

public static Session getSession(){
return getSessionFactory().getCurrentSession();
}

public static SessionFactory getSessionFactory(){
if (sessionFactory ==null || sessionFactory.isClosed()) {
sessionFactory = new Configuration().configure().buildSessionFactory();
}
return sessionFactory;
}


}
0 0