2013-07-31 87 views
1

我是新手hibernate.I嘗試了我的第一個hibernate程序,但沒有成功。運行我的hibernate程序時出現以下錯誤。XML解析運行休眠時出錯

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 

這是hibernate的配置文件。

<?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> 

回答

2

簡單,您的評論是不是註釋:

<! -- autocommit false --> 

應該

<!-- autocommit false --> 

你有一個額外的空間...

你應該能夠在源代碼中突出顯示 - 正如卓越的SO所展示的那樣源高亮顯示。通過刪除高炮空間

<! -- autocommit false --> 

修復:

1

您有任何意見不好界定,搜索此!和 -