【问题标题】:XML Parsing Error - HibernateXML 解析错误 - 休眠
【发布时间】:2014-04-13 14:50:33
【问题描述】:

我正在尝试运行我的第一个 Hibernate 程序。 我无法弄清楚问题所在,因为匹配的结束标签实际上存在? 提前感谢您的帮助!

Error parsing XML: /hibernate.cfg.xml(11) The element type "session-factory" must be terminated by the matching end-tag

hibernate.cfg.xml:

<?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="hibernate.connection.driver_class" /> com.mysql.jdbc.Driver </property>
        <property name="hibernate.connection.url"/>jdbc:mysql://localhost:3306/westbahn</property>
        <property name="hibernate.connection.username" />root</property>
        <property name="hibernate.connection.password" />secretpassword</property>
        <property name="hibernate.dialect" />org.hibernate.dialect.MySQLInnoDBDialect</property>




        <property name="connection.pool_size">1</property>

        <property name="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect" </property>

        <property name="show_sql">true</property>

        <property name="current_session_context_class">thread</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

        <property name="hibernate.hbm2ddl.auto">create</property>

    </session-factory>
</hibernate-configuration>

【问题讨论】:

  • XML 中没有根 hibernate-configuration 元素。也没有开放会话工厂元素。显示整个文件。从第一行到最后一行。
  • 您的“物业”标签为空:&lt;property name="hibernate.connection.driver_class" /&gt; ... &lt;/property&gt;。从第一个标签中删除/&lt;property name="hibernate.connection.driver_class" &gt;
  • 非常感谢,它正在工作,这是一个多么令人尴尬的错误..

标签: java mysql xml hibernate


【解决方案1】:

Hibernate 配置文件应该是这样的

    <hibernate-configuration>
    <session-factory>
    <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
    <property name="connection.user">xxx</property>
    <property name="connection.password">xxxx</property>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
    <property name="show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">create</property>   
    <mapping resource="xxxx.hbm.xml"/>
     </session-factory>
</hibernate-configuration>

这可以帮助你!

【讨论】:

    【解决方案2】:

    您的 5 个第一个属性元素是错误的:尽管它们有一个主体,但您使用了自闭合元素。例如:

    <property name="hibernate.connection.driver_class" /> com.mysql.jdbc.Driver </property>
    

    应该是

    <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property>
                                      no slash here --^
    

    【讨论】:

      猜你喜欢
      • 2010-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 2012-05-14
      • 2016-02-26
      相关资源
      最近更新 更多