java - 找不到元素 'hibernate-configuration' 的声明但它存在

标签 java hibernate

这是我的配置:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-5.0.dtd">
<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">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>

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

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</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/hibernate/tutorial/domain/Event.hbm.xml"/>

    <mapping class="Mapping.AccountMap"
  </session-factory>
</hibernate-configuration>

我读到我应该更改“Doctype”并且我根据我找到的其他答案做了,但是出现了这个错误:

无法在 RESOURCE hibernate.cfg.xml 中的第 8 行和第 63 列执行解码。消息:cvc-elt.1:找不到元素“hibernate-configuration”的声明。

最佳答案

你的 dtd url 是假的......好像 hibernate-configuration-5.0.dtd 不存在......使用这个:

http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd

改变整个标题:

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

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

关于java - 找不到元素 'hibernate-configuration' 的声明但它存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32963094/

相关文章:

java - 是否可以从 Java 调用 COM API?

java - 使用 Jackson 自定义 POJO 序列化

java - 更简洁的正则表达式?

database - 如何在 Grails 中使用 Hibernate 索引?

java - Hibernate/JPA 使用标准作为注释

java - 如何打印查询的字段?

java - spring jpa中如何管理数据库连接池?

java - java和ntdll.dll之间的关系

java - 为什么 Swarm 注册 "jpa"、 "undertow"缓存容器

java - gethibernatetemplate().save(object) 不持久化数据