hibernate的头痛问题,高手请帮帮我

javasgt 2008-09-17 10:02:59
启动tomcat服务器时没有报错,当提交请求时就出错了

报错如下
javax.servlet.ServletException: org.hibernate.HibernateException: [color=#FF0000]Could not parse configuration:
org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.[/color]
配置文件如下:
hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/sas?useUnicode=true&characterEncoding=UTF-8
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<!-- property name="hibernate.connection.pool_size"></property -->
<!-- dialect for MySQL -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<mapping resource="sas/properties/Customer.hbm.xml" />
<mapping resource="sas/properties/Suggestion.hbm.xml" />
</session-factory>
</hibernate-configuration>
Customer.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="sas.beans.synbean">
<class
name="Customer"
table="customer"
>
<meta attribute="sync-DAO">true</meta>
<id
name="Id"
type="integer"
column="id"
>
<generator class="increment"/>
</id>

<property
name="CustomerName"
column="customerName"
type="string"
not-null="true"
length="45"
/>
<property
name="CustomerPwd"
column="customerPwd"
type="string"
not-null="true"
length="45"
/>


<set name="Suggestions" inverse="true" lazy="true">
<key column="id"/>
<one-to-many class="Suggestion"/>
</set>
</class>
</hibernate-mapping>

Suggestion.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="sas.beans.synbean">
<class
name="Suggestion"
table="suggestion"
>
<meta attribute="sync-DAO">true</meta>
<id
name="Id"
type="integer"
column="id"
>
<generator class="increment"/>
</id>

<property
name="Topic"
column="topic"
type="string"
not-null="true"
length="45"
/>
<property
name="Content"
column="content"
type="string"
not-null="true"
length="120"
/>
</class>
</hibernate-mapping>

请高手帮帮我吧,弄了几天了谢谢了
...全文
241 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinsu_st 2008-09-19
  • 打赏
  • 举报
回复
把配置文件扔到src目录下,或者直接扔到web-inf/classes目录下
notcool 2008-09-19
  • 打赏
  • 举报
回复
楼主将hibernate.cfg.xml改成属性文件格式配置~
出现这个错误应该是xml文件解析错误,可能是dom4j版本的问题
javasgt 2008-09-18
  • 打赏
  • 举报
回复
我把hibernate.cfg.xml放在了sas/properties/hibernate.cfg.xml
ITwuyijun 2008-09-18
  • 打赏
  • 举报
回复
你配置没有问题:他出的是Servlet异常
你再检查你那个Action类有没有错
Dave 2008-09-18
  • 打赏
  • 举报
回复
最好是放在web-inf目录下。
nynklove 2008-09-18
  • 打赏
  • 举报
回复
你把hibernate.cfg.xml放在src根目录下试试
javasgt 2008-09-18
  • 打赏
  • 举报
回复
配置文件的完整路径是
sas/WEB-INF/src/sas/properties/hibernate.cfg.xml

ACTION应该没错,我没有使用hibernate时都是正常的
luhao 2008-09-18
  • 打赏
  • 举报
回复
看这个
http://www.cnblogs.com/kaixin110/archive/2007/12/25/1013722.html
http://blog.csdn.net/yukikaze/archive/2008/04/24/2321784.aspx
如一宝宝 2008-09-17
  • 打赏
  • 举报
回复
Could not parse configuration
找不到配置文件,
lz把hibernate.cfg.xml放在哪里了
ren8388 2008-09-17
  • 打赏
  • 举报
回复
只有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>
<property name="hibernate.format_sql">true</property>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/sas
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">root</property>
<property name="connection.password">123456</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<mapping resource="sas/properties/Customer.hbm.xml" />
<mapping resource="sas/properties/Suggestion.hbm.xml" />

</session-factory>

</hibernate-configuration>



67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧