我在hibernate.cfg.xml文件里配置了<property name="current_session_context_class">thread</property>
同时获取Session使用的是factory.getCurrentSession()方法,请问使用这种方式还需要手动关闭线程吗?以前别人写的方法是用的factory.openSession()方法,整个Util类是这样写的:public class HibernateUtil {
static SessionFactory factory = null;
static ThreadLocal<Session> t = new ThreadLocal<Session>();

static{
try{
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
}catch(Exception e){
e.printStackTrace();
throw new ExceptionInInitializerError();
}
}
//创建资源
public static Session getSession() throws Exception{
Session session = null;

Session s = t.get();
//判断当前线程是否持有有效session
if(s == null){
if(factory != null){
session = factory.openSession();
s = session;
//将当前session和线程绑定
t.set(s);
}
}
return s;
}

//关闭资源
public static void close() throws Exception{
Session s = t.get();
if(s != null){
s.close();
//解除当前session和线程的绑定
t.set(null);
}
}
}
请问:如果使用factory.getCurrentSession()方法还需要这样手动关闭线程吗?谢谢~