[code="java"]package com.pb.hibernate.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static Session session;
private HibernateUtil(){}
static{
buildSession();
}
private static void buildSession(){
Configuration config=new Configuration().configure();
SessionFactory sf=config.buildSessionFactory();
session=sf.openSession();
}
public static Session getSession(){
if (session==null) {
buildSession();
}
return session;
}
public static void closeSession(){
if (session!=null) {
session.close();
}
}
}[/code] 这是我们老师写的代码,一个Hibernate的工具类,23行好像有问题,session关闭后不为空,就不会执行buildSession()这个方法,然后就一直报session is closed,求修正