xoxobool

成功者,永远成功,失败者,永远失败,我要面对者,走向成功!

导航

Hibernate框架概念

1.Hibernate是ORM框架,完成对象的持久化操作。

2.允许开发者采用面向对象的方式来操作数据库。

3.安装Hibernate的插件到Eclipse中来自动生成配置文件。

4.Hibernate环境搭建

 5.测试连接数据库

package com.hanqi.test;



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() {
    
        //1 获取配置文件
        Configuration cfg = new Configuration().configure();
        //2 注册配置
        ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
        //3 获取SessionFactory(相当于JDBC的连接)
        SessionFactory sf=cfg.buildSessionFactory(sr);
        System.out.println(sf);
        sf.close();
    }  

}

 

posted on 2016-11-07 20:18  春之林木  阅读(177)  评论(0编辑  收藏  举报