0%

HIBERNATE4—CURD工具类

下面是个简单的例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.wqc.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class hbnUtils {
private static SessionFactory sessionFactory;
public static Session getSession() {

return sessionFactory.getCurrentSession();
}
public static SessionFactory getSessionFactory() {
if(sessionFactory==null ||sessionFactory.isClosed()) {
sessionFactory=new Configuration().buildSessionFactory();
}
return sessionFactory;
}
}