mysql - JAVA使用Hibernate的SchemaExport无法生成表

 兴添刚 发布于 2022-10-28 14:59

代码如下

  • 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'
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有