读书人

新手请问:Could not parse configura

发布时间: 2012-08-21 13:00:21 作者: rapoo

新手请教:Could not parse configuration: /hibernate.cfg.xml
才开始学hibernate,对着网上的一个小例子操作。结果出现如下问题:

Java code
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).log4j:WARN Please initialize the log4j system properly.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1380)    at org.hibernate.cfg.Configuration.configure(Configuration.java:1314)    at org.hibernate.cfg.Configuration.configure(Configuration.java:1300)    at com.elva.hibernate.UserTest.main(UserTest.java:7)Caused by: org.dom4j.DocumentException: Error on line 11 of document  : The string "--" is not permitted within comments. Nested exception: The string "--" is not permitted within comments.    at org.dom4j.io.SAXReader.read(SAXReader.java:482)    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1370)    ... 3 more


一直找不到原因,请高手不吝赐教!谢谢!
配置文件:
User.hbm.xml
XML code
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping> <class name="com.elva.hibernate.User" table="myusertable">   <id name="id"><generator class="identity" /></id>   <property name="username" type="string" />   <property name="password" type="string" />   <property name="email" type="string" /></class></hibernate-mapping>


hibernate.cfg.xml
[code=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="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">root</property>

<!-- JDBC connection pool (use the built-in)--<property name="hibernate.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.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">create</property>>

<!-- mapping resources -->
<mapping resource="com/elva/hibernate/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
[code]

------解决方案--------------------


XML code
<?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="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">root</property>     <!-- JDBC connection pool (use the built-in)-->  <property name="hibernate.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.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">create</property>    <!-- mapping resources -->   <mapping resource="com/elva/hibernate/User.hbm.xml"/> </session-factory> </hibernate-configuration> 

读书人网 >Java Web开发

热点推荐