hbnutil.java
来自「hibernate映射1对多的课堂代码」· Java 代码 · 共 38 行
JAVA
38 行
package com.sd0709.enrollment.util;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class HbnUtil {
private static SessionFactory sf;
private Session s;
private Transaction tran;
static {
try {
sf=new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
e.printStackTrace();
}
}
public static Session getSession(){
Session s=null;
try {
if(sf!=null&&!sf.isClosed()){
s=sf.openSession();
}
} catch (HibernateException e) {
e.printStackTrace();
}
return s;
}
public static void releaseSeesion(Session s){
if(s!=null&&s.isOpen()) s.close();
}
public static void clearSessionFactory(){
if(sf!=null&&!sf.isClosed()) sf.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?