简体   繁体   English

线程“main”中的异常org.hibernate.MappingException:hibernate4中的配置无效

[英]Exception in thread “main” org.hibernate.MappingException: invalid configuration in hibernate4

I am stuck with hibernate configuration file exception, this is my hibernate.cfg.xml file: 我遇到了hibernate配置文件异常,这是我的hibernate.cfg.xml文件:

<?xml version='1.0' encoding='utf-8'?>

<hibernate-configuration
        xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
        xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
    <property name="connection.username">postgresql</property>
    <property name="connection.password">password</property>

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

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

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

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.internal.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">update</property>
    <mapping resource="org.person.PersonModel"/>
  </session-factory>
</hibernate-configuration>

I am using hibernate-core-4.1.12.Final.jar, I am getting the following exception: 我正在使用hibernate-core-4.1.12.Final.jar,我收到以下异常:

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: invalid configuration
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2022)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1939)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1918)
    at org.person.PersonPersistance.main(PersonPersistance.java:14)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; Document is invalid: no grammar found.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

By seeing the respective exception I came to know that I have some mistake in my configuration file. 通过查看相应的异常,我发现我的配置文件中有一些错误。 I want to know what mistake I have done in my configuration file. 我想知道我在配置文件中犯了什么错误。

When I wrote same program in Eclipse Luno, it has got execute. 当我在Eclipse Luno中编写相同的程序时,它已经执行了。 Try this and see. 试试看,看看。

Add this before <hibernate-configuration> tag: <hibernate-configuration>标记之前添加:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

With Hibernate 4.x you should use the same DTD as 3.x: 使用Hibernate 4.x,你应该使用与3.x相同的DTD:

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

 <hibernate-configuration>

 <session-factory>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate:线程“ main” org.hibernate.MappingException中的异常:无效的配置 - Hibernate: Exception in thread “main” org.hibernate.MappingException: invalid configuration 线程“main”中的异常org.hibernate.MappingException:配置无效 - Exception in thread “main” org.hibernate.MappingException: invalid configuration Hibernate org.hibernate.MappingException:无效的配置 - Hibernate org.hibernate.MappingException: invalid configuration 线程“main”中的异常org.hibernate.MappingException:未知实体: - Exception in thread “main” org.hibernate.MappingException: Unknown entity: 线程“ main” org.hibernate.MappingException中的异常:未知实体:Ville - Exception in thread “main” org.hibernate.MappingException: Unknown entity: Ville 线程“main”中的异常 org.hibernate.MappingException:未知实体 - Exception in thread "main" org.hibernate.MappingException: Unknown entity 线程“ main”中的异常org.hibernate.MappingException:未知实体:org.hibernate.internal.SessionImpl - Exception in thread “main” org.hibernate.MappingException: Unknown entity: org.hibernate.internal.SessionImpl 线程“main”中的异常org.hibernate.MappingException:未知实体:org.hibernate.employee - Exception in thread “main” org.hibernate.MappingException: Unknown entity: org.hibernate.employee 线程“主” org.hibernate.MappingException中的异常:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数 - Exception in thread “main” org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister HIBERNATE4 org.hibernate.MappingException:未知实体 - HIBERNATE4 org.hibernate.MappingException: Unknown entity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM