码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate基础工具类

时间:2017-05-20 14:59:31      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:span   runtime   color   blog   ati   UI   ide   return   read   

 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基础工具类

标签:span   runtime   color   blog   ati   UI   ide   return   read   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!