继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Hibernate5.0版本创建SchemaExport对象。

KelvinMario
关注TA
已关注
手记 1
粉丝 0
获赞 2
package entity;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;

public class TestStudents {
    @Test
    public void testSchemaExport(){
        //创建配置对象
        Configuration config = new Configuration().configure();
        //创建服务注册对象
        //ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();  
        //创建sessionFactory
        SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
        //创建session对象
        Session session = sessionFactory.getCurrentSession();
        //创建SchemaExport对象
         MetadataImplementor metadata = (MetadataImplementor)new MetadataSources( serviceRegistry ).buildMetadata();  
         new SchemaExport(metadata).create(true, true);  
    }

}
打开App,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP