您的位置:首页 > 运维架构 > Linux

CentOS 国内yum源

2016-01-19 11:57 465 查看
public
 
class
 HibernateUtil { 

        
public
 
static
 
final
 SessionFactory sessionFactory; 

             
static
 { 

                   
try
 { 

                        sessionFactory 
=
 
new
 Configuration().configure() 

                                  .buildSessionFactory(); 

                   } 
catch
 (Throwable ex) { 

                        
throw
 
new
 ExceptionInInitializerError(ex); 

             } 

        } 

        
public
 
static
 
final
 ThreadLocal
<
Session
>
 session 
=
 

                                
new
 ThreadLocal
<
Session
>
(); 

        
public
 
static
 Session currentSession() 
throws
 HibernateException { 

              Session s 
=
 session.get(); 

              
if
(s 
==
 
null
) { 

                    s 
=
 sessionFactory.openSession(); 

                    session.set(s); 

              } 

              
return
 s; 

        } 

        
public
 
static
 
void
 closeSession() 
throws
 HibernateException { 

              Session s 
=
 session.get(); 

              
if
(s 
!=
 
null
) { 

                    s.close(); 

              } 

              session.set(
null
); 

        } 

   }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: