Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在hibernate配置中未创建表_Java_Hibernate - Fatal编程技术网

Java 在hibernate配置中未创建表

Java 在hibernate配置中未创建表,java,hibernate,Java,Hibernate,我编写了一个hibernate util类来加载配置文件并在中打开会话,我同时使用xml和属性文件,似乎属性文件已经加载,但是一切都很顺利,但是表没有创建 这是 HibernateUtilNew.java package com.javarnd.cip.db; import java.util.Properties; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.

我编写了一个hibernate util类来加载配置文件并在中打开会话,我同时使用xml和属性文件,似乎属性文件已经加载,但是一切都很顺利,但是表没有创建

这是 HibernateUtilNew.java

package com.javarnd.cip.db;

import java.util.Properties;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

import com.javarnd.cip.util.PropertiesUtil;

public class HibernateUtilNew {

    private static final SessionFactory sessionFactory;
    private static Properties properties = new Properties();
    private static Configuration configuration=new Configuration();


    static {
        try {
            properties = PropertiesUtil.propertyLoad();
            configuration.configure("hibernate.cfg.xml").addProperties(properties);
            ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                        .applySettings(configuration.getProperties())
                        .build();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session openSession() {
        return sessionFactory.openSession();
    }

    public static void shutdown() {
        sessionFactory.close();
    }

    public static void main(String[] argss) {
        openSession();
        System.out.println("connection open");
//      shutdown();
//      System.out.println("connection closed successfully");
    }
}
休眠配置属性

hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/testcip
hibernate.connection.username=root
hibernate.connection.password=root
#hibernate.connection.pool_size=10
hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
show_sql=true
format_sql=true
use_sql_comments=true
hbm2ddl.auto=create
Mar 05, 2019 11:44:53 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.4.1.Final}
Mar 05, 2019 11:44:54 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Mar 05, 2019 11:44:54 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Mar 05, 2019 11:44:54 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/testcip]
Mar 05, 2019 11:44:54 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Mar 05, 2019 11:44:54 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Mar 05, 2019 11:44:54 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Mar 05, 2019 11:44:54 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
Mar 05, 2019 11:44:55 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
connection open
hibernate.cfg.xml

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <property name="hibernate.dialect"></property>
        <property name="hibernate.connection.driver_class"></property>
        <property name="hibernate.connection.url"></property>
        <property name="hibernate.connection.username"></property>
        <property name="hibernate.connection.password"></property>
        <property name="show_sql"></property>
        <property name="format_sql"></property>
        <property name="use_sql_comments"></property>
        <property name="hbm2ddl.auto"></property>

        <!-- mapping files -->
        <mapping class="com.javarnd.cip.model.Country" />
        <mapping class="com.javarnd.cip.model.City" />
        <mapping class="com.javarnd.cip.model.Language" />
        <mapping class="com.javarnd.cip.model.Sports" />
        <mapping class="com.javarnd.cip.model.Userdetail" />
    </session-factory>
</hibernate-configuration>
package com.javarnd.cip.util;

import java.util.Properties;

public class PropertiesUtil {
    public static Properties propertyLoad() {
        Properties properties = null;
        if (properties == null) {
            properties = new Properties();
            try {
                properties.load(PropertiesUtil.class
                        .getResourceAsStream("/hibernate_config.properties"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return properties;
    }
}
使用addProperties()进行堆栈跟踪

目录结构和文件位置


请向我推荐解决方案

你能发布整个stacktrace吗?嘿,看看我的编辑关于PropertiesUtil.propertyLoad()的内容是什么?嘿,看看我的编辑这些文件在哪里?在“资源”下?你能发布整个stacktrace吗?嘿,看我的编辑关于PropertiesUtil.propertyLoad()的内容是什么?看我的编辑这些文件在哪里?在“资源”下?
package com.javarnd.cip.util;

import java.util.Properties;

public class PropertiesUtil {
    public static Properties propertyLoad() {
        Properties properties = null;
        if (properties == null) {
            properties = new Properties();
            try {
                properties.load(PropertiesUtil.class
                        .getResourceAsStream("/hibernate_config.properties"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return properties;
    }
}