Hibernate 配置

package com.shuyinghengxie.doudou;

import static org.junit.Assert.*;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.junit.Test;

public class TEST01 {

    
    //测试 Hibernate连接
    @Test
    public void test() 
    {
        //获取配置文件 
        Configuration cfg = new Configuration().configure() ;
        
        //注册配置  
        ServiceRegistry sr = new StandardServiceRegistryBuilder().
                                            applySettings(cfg.getProperties()).build();
        
        //获取SessionFactory
        SessionFactory sf = cfg.buildSessionFactory(sr) ;

        //System.out.println(sf);
        
        sf.close(); //关闭,释放资源
    }

}

 

posted @ 2016-11-07 18:06  丶疏影横斜  阅读(149)  评论(0编辑  收藏  举报