hibernate.cfg.xml
root
123456
org.mariadb.jdbc.Driver
jdbc:mariadb://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
org.hibernate.dialect.MySQLDialect
true
true
update
thread
TestStudents.java
package entity;
import java.util.EnumSet;
//import org.hibernate.Session;
//import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.junit.Test;
public class TestStudents {
@Test
public void testSchemaExport() {
//创建配置对象
Configuration config = new Configuration().configure();
//创建服务注册对象
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
//创建sessionFactory
//SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
//创建session对象
//Session session = sessionFactory.getCurrentSession();
//创建SchemaExport对象
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.DATABASE), metadata);
}
}
控制台输出
四月 02, 2017 6:36:11 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.9.Final}
四月 02, 2017 6:36:11 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
四月 02, 2017 6:36:12 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
四月 02, 2017 6:36:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
四月 02, 2017 6:36:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.mariadb.jdbc.Driver] at URL [jdbc:mariadb://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8]
四月 02, 2017 6:36:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
四月 02, 2017 6:36:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
四月 02, 2017 6:36:12 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
四月 02, 2017 6:36:12 下午 org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
四月 02, 2017 6:36:12 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
四月 02, 2017 6:36:12 下午 org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@446293d'
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
闭关修行中......