1

我是休眠的新手。我尝试了我的第一个休眠程序但没有成功。运行休眠程序时出现以下错误。

Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: Hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1586)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1520)
    at com.test.Test.main(Test.java:16)
Caused by: org.dom4j.DocumentException: Error on line 11 of document  : The content of elements must consist of well-formed character data or markup. Nested exception: The content of elements must consist of well-formed character data or markup.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1576)
    ... 2 more 

这是休眠配置文件。

<?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>
<!-- connecting database -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test123</property>
<! -- autocommit false -->
<property name="hibernate.connection.autocommit">false</property>

<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<!-- for jdbc transaction -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<mapping resource="mapping.hbm.xml">
</mapping>
</session-factory>
</hibernate-configuration>
4

2 回答 2

2

很简单,您的评论不是评论:

<! -- autocommit false -->

应该

<!-- autocommit false -->

你有一个额外的空间...

您应该能够在源代码突出显示中看到这一点 - 正如出色的 SO 源突出显示所证明的那样。

于 2013-07-31T09:34:32.600 回答
1

你有一个错误分隔的评论,搜索这个:

<! -- autocommit false -->

通过删除空间 beteen 来修复它!和 -

于 2013-07-31T09:34:40.850 回答