📄 hibernatetools.java
字号:
package com.test.bbs.dao.impl;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public final class HibernateTools {
private static SessionFactory sessionFactory;
private static ThreadLocal session = new ThreadLocal();
private HibernateTools() {
}
static {
sessionFactory = new Configuration().configure(
"com/test/bbs/dao/impl/hibernate.cfg.xml")
.buildSessionFactory();
}
@SuppressWarnings("unchecked")
static Session getCurrentSession() {
Session s = (Session) session.get();
if (s != null)
return s;
s = sessionFactory.openSession();
session.set(s);
return s;
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -