Junit測試沒有自動(dòng)生成表
控制臺信息如下:
四月 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&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&characterEncoding=UTF-8]
和慕課網(wǎng)教程區(qū)別就是,我是hibernate5,下面這個(gè)改了
//創(chuàng)建服務(wù)注冊對象
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
而且由于之前報(bào)錯(cuò)沒有hibernate.properties,我手動(dòng)添加了個(gè)hibernate.properties空白文件
2017-04-22
public void init(){
?? ??? ?System.out.println("init()");
?? ??? ?//創(chuàng)建配置對象
?? ??? ?Configuration config=new Configuration().configure();
?? ??? ?
?? ??? ?//服務(wù)注冊對象
?? ??? ?final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
//?? ??? ?ServiceRegistry serviceRegistry=new StandardServiceRegistryBuilder().
//?? ??? ??? ??? ?applySettings(config.getProperties()).build();
?? ??? ?//創(chuàng)建會(huì)話工廠對象
//?? ??? ?sessionfactory=config.buildSessionFactory(serviceRegistry);
?? ??? ?
?? ??? ?sessionfactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
?? ??? ?//會(huì)話對象
?? ??? ?session=sessionfactory.openSession();
?? ??? ?
?? ??? ?//開啟事務(wù)
?? ??? ?transaction=session.beginTransaction();
?? ??? ?
?? ??? ?
?? ?}