首页 > Web开发 > 详细

Hibernate基础工具类

时间:2017-05-20 14:48:44      阅读:335      评论:0      收藏:0      [点我收藏+]
 1 import org.hibernate.Session;
 2 import org.hibernate.SessionFactory;
 3 import org.hibernate.cfg.Configuration;
 4 
 5 public class Hibernate_Util {
 6 
 7     private static SessionFactory factory;
 8 
 9     static {
10         Configuration configure = new Configuration().configure();
11         factory = configure.buildSessionFactory();
12         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
13 
14             @Override
15             public void run() {
16                 System.out.println("资源关闭了");
17                 factory.close();
18             }
19         }));
20     }
21 
22     public static Session openSession() {
23         Session session = factory.openSession();
24         return session;
25     }
26 
27     public static Session getCurrentSession() {
28         Session session = factory.getCurrentSession();
29         return session;
30     }
31 }

 

Hibernate基础工具类

原文:http://www.cnblogs.com/1-cos/p/1-cos.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!