Junit测试没有自动生成表

来源:1-10 使用JUnit进行测试

秦家小小神

2017-04-22 15:28

控制台信息如下:

四月 22, 2017 3:18:09 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {5.2.6.Final}

四月 22, 2017 3:18:10 下午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}

四月 22, 2017 3:18:10 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}

四月 22, 2017 3:18:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)

四月 22, 2017 3:18:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql:///hibernate?useUnicode=true&amp;characterEncoding=UTF-8]

四月 22, 2017 3:18:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001001: Connection properties: {user=root, password=****}

四月 22, 2017 3:18:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001003: Autocommit mode: false

四月 22, 2017 3:18:10 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>

INFO: HHH000115: Hibernate connection pool size: 20 (min=1)

四月 22, 2017 3:18:11 下午 org.hibernate.dialect.Dialect <init>

INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect

四月 22, 2017 3:18:12 下午 org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources

INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@1caedad'

四月 22, 2017 3:18:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop

INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql:///hibernate?useUnicode=true&amp;characterEncoding=UTF-8]

和慕课网教程区别就是,我是hibernate5,下面这个改了

//创建服务注册对象

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

而且由于之前报错没有hibernate.properties,我手动添加了个hibernate.properties空白文件

写回答 关注

1回答

  • Fader
    2017-04-22 17:23:13
    已采纳

    public void init(){
            System.out.println("init()");
            //创建配置对象
            Configuration config=new Configuration().configure();
            
            //服务注册对象
            final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
    //        ServiceRegistry serviceRegistry=new StandardServiceRegistryBuilder().
    //                applySettings(config.getProperties()).build();
            //创建会话工厂对象
    //        sessionfactory=config.buildSessionFactory(serviceRegistry);
            
            sessionfactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
            //会话对象
            session=sessionfactory.openSession();
            
            //开启事务
            transaction=session.beginTransaction();
            
            
        }

    秦家小小神

    灰常感谢!

    2017-04-23 21:11:55

    共 1 条回复 >

Hibernate初探之单表映射

Java持久化框架Hibernate入门教程,掌握Hibernate基本概念

74810 学习 · 793 问题

查看课程

相似问题