Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.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
我认为我的应用程序没有读取hibernate配置文件_Hibernate - Fatal编程技术网

我认为我的应用程序没有读取hibernate配置文件

我认为我的应用程序没有读取hibernate配置文件,hibernate,Hibernate,它没有读取带注释的类,也没有读取drop和recreate database schema while startup属性,而不是这些,当我硬编码如下语句时 config.addAnnotatedClass(UserDetail.class); this is for making annotation class visible to my application and new SchemaExport(config).create(true, true); this is for rec

它没有读取带注释的类,也没有读取drop和recreate database schema while startup属性,而不是这些,当我硬编码如下语句时

config.addAnnotatedClass(UserDetail.class); this is for making annotation class visible to my application and

new SchemaExport(config).create(true, true); this is for recreate database schema while startup property.
上面的两条语句工作正常,但如果没有这两条语句,我们可以通过配置文件读取它们,即使是我做的,也不能读取。为什么?

这是我的配置文件

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/testDb</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <!--  <property name="hibernate.default_schema">TESTSCHEMA</property> -->

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Enable Hibernate's current session context -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup --> 
        <property name="hbm2ddl.auto">create</property>

        <!-- name of the annotated entity class -->
        <mapping class="com.hibernate.CollectionDemo.UserDetail"/>

        <!--<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
        <mapping resource="org/hibernate/tutorial/domain/Person.hbm.xml"/>

    -->
    </session-factory>

</hibernate-configuration>

不要以为检查它。编码是二进制的,或者是二进制的,或者不是二进制的。是的,我甚至试过我上面所说的。我也提到过。配置文件的名称是什么,您如何初始化它,共享代码。名称是hibernate.cfg.xml,我已经在这里共享了配置文件。只是没有用main class.new SchemaExport(config.create)(true,true)更新;不会创建新的数据库架构,它会导出当前数据库架构,参数为(将\u日志导出到\u控制台,将\u脚本导出到\u数据库)。
package com.hibernate.CollectionDemo;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;


public class TestUserDetail 
{
public static void main(String[] args)
{
    UserDetail usrd=new UserDetail();

    Configuration config=new Configuration();
    config.addAnnotatedClass(UserDetail.class);
            config.configure("hibernate.cfg.xml");
            new SchemaExport(config).create(true, true);

            SessionFactory sf=config.buildSessionFactory();

            Session s=sf.openSession();
            s.beginTransaction();

            usrd.setUserName("FirstUser");

            Address addr=new Address();
            addr.setCity("CN");
            addr.setPincode("16345");
            addr.setState("TN");
            addr.setStreetName("t-nagar");

            Address addr2=new Address();
            addr2.setCity("hyd");
            addr2.setPincode("5845");
            addr2.setState("AP");
            addr2.setStreetName("pet");

            usrd.getListOfAddress().add(addr);
            usrd.getListOfAddress().add(addr2);

            s.save(usrd);
            s.getTransaction().commit();

}
}