?? hibernateutil.java
字號:
package cn.com.tarena.ecport.common.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* <pre>
* Hibernate的工具類
* 通過此類可以方便地使用Hibernate來管理持久層
* </pre>
*
* @author zhouyu 2008-1-16
*/
public class HibernateUtil {
/**
* Hibernate的sessionFactory
* 通過sessionFactory可以創建Hibernate的session
*/
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure()
.buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
/**
* 返回Hibernate的sessionFactory
* @return sessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* <pre>
* 獲得“當前”Hibernate的Session
* “當前”的含義可根據Hibernate配置文件中的
* hibernate.current_session_context_class來
* 配置,詳細請參考Hibernate文檔
* </pre>
* @return “當前”Hibernate的Session
*/
public static Session getCurrentSession(){
return HibernateUtil.getSessionFactory().getCurrentSession();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -