您的位置:首页 > 其它

hibernate连接工具类

2016-07-13 21:03 197 查看
<span style="font-size:14px;">package com.yfly.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* hibernate连接
* @author yFly
*
*/
public class HibernateUtils {

private static SessionFactory sessionFactory;

static {
sessionFactory = new Configuration().configure().buildSessionFactory();
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

public static Session getSession() {
return sessionFactory.openSession();
}

public static void close(Session session) {
if(session != null) {
if(session.isOpen()) {
session.close();
}
}
}
}
</span>

jia包:...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: