java - 线程中的异常 "main"org.hibernate.MappingException : invalid configuration in hibernate4

标签 java jakarta-ee hibernate-4.x

我遇到了 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>

我正在使用 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)

通过查看相应的异常,我发现我的配置文件中有一些错误。我想知道我的配置文件中犯了什么错误。

最佳答案

当我在 Eclipse Luno 中编写相同的程序时,它已得到执行。试试这个看看。

<hibernate-configuration> 之前添加此内容标签:

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

关于java - 线程中的异常 "main"org.hibernate.MappingException : invalid configuration in hibernate4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22452593/

相关文章:

Java JPanel 闪烁

java - 程序中未触发异常处理/意外行为

java/jsf 奇怪的错误 : WARNING: StandardWrapperValve PWC1406: Servlet. service() ...抛出异常 java.lang.NullPointerException

slf4j - Hibernate 4 Wildfly 8 日志记录不起作用

java - 将 Hibernate 4.3 迁移到 5.2 - 缺少表

Java 字符串拆分为 "."(点)

java - 在 GSON 反序列化期间识别无效字段值

java - 有没有办法在运行时确定 Java EE 版本?

java - 将游戏部署到服务器会导致奇怪的行为

java - Hibernate 从 3 个 SerializedBlob 类迁移到 4 个 SerializedBlob 类 已弃用