HibernateUtil.java
package com.hibernate.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil
{
private static SessionFactory sessionFactory;
static
{
try
{
sessionFactory = new Configuration().configure()
.buildSessionFactory();
}
catch (Exception ex)
{
System.err.println("构造SessionFactory异常发生: " + ex.getMessage());
}
}
public static Session currentSession()
{
Session session = sessionFactory.openSession();
return session;
}
public static void closeSession(Session session)
{
if (null != session)
{
session.close();
}
}
}
最新内容请见作者的GitHub页:http://qaseven.github.io/
时间: 2024-09-20 17:32:05