<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包:...