2014-05-12 150 views
0

enter image description here你好我綁,使用戶登記表簡單的Web應用程序使用JSP和休眠當我運行我的應用程序我得到以下ExeptionMappingNotFoundException:資源:user.hbm.xml找不到

MappingNotFoundException: resource: user.hbm.xml not found 

這裏是我的代碼

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

<!-- Generated by MyEclipse Hibernate Tools.     --> 
**hibernate.cfg.xml** 
    <hibernate-configuration> 

      <session-factory> 
      <property name="hbm2ddl.auto">update</property> 
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
      <property name="connection.url">jdbc:mysql://localhost:3306/employee</property> 
      <property name="connection.username">root</property> 
      <property name="connection.password"></property> 
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
      <property name="show_sql">true</property> 
     <mapping resource="hiber/user.hbm.xml"/> 
     </session-factory> 

    </hibernate-configuration> 

user.hbm.xml

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

      <hibernate-mapping> 
      <class name="User" table="u400"> 
      <id name="id"> 
      <generator class="increment"></generator> 
      </id> 
      <property name="name"></property> 
      <property name="password"></property> 
      <property name="email"></property> 
      </class> 
      </hibernate-mapping> 

項目結構如下

Project 
    | 
    |-WebPages 
    | 
    |-src 
    |-hiber 
    | |-user.java 
     |-UserDao.java 
     |-user.hbm.xml 
     |-hibernate.cfg.xml 

如何刪除這個例外,我應該怎麼做事先

由於得到以下異常

type Exception report 

messageInternal Server Error 

descriptionThe server encountered an internal error that prevented it from fulfilling this request. 

exception 

org.apache.jasper.JasperException: org.hibernate.HibernateException: Could not parse configuration: /hiber/hibernate.cfg.xml 

root cause 

org.hibernate.HibernateException: Could not parse configuration: /hiber/hibernate.cfg.xml 

root cause 

org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net 

回答

1

檢查休眠和罐子版本DTD版本進行比較這裏面hibernate.cfg.xml

應該基本一致,否則它無法解析的依賴關係。希望的

<mapping resource="user.hbm.xml"/> 

代替

<mapping resource="hiber/user.hbm.xml"/> 

它的工作對我來說,你:

+0

我正在使用hibernet 3.0 jar和dtd版本的文件是3.0 – user3598351

+1

okie ..然後嘗試從hibernate.cfg.cml中刪除encoding ='UTF-8' –

+0

它的工作原理感謝 – user3598351

0

你可以嘗試充分hibernate.cfg.xml中的user.hbm.xml路徑。

<mapping resource="hiber/user.hbm.xml"/> 
+0

我在我的文章中添加完整路徑 – user3598351

+0

根據您的項目結構,您的hbm文件位於hiber文件夾內。 –

+0

我做了這個,現在我得到了其他豁免 – user3598351

0

不要在映射資源使用的完整路徑。

0

愚蠢的錯誤: - 您的pojo /持久類有「User.java」名稱,以大寫'U'開頭,但映射文件「user.hbm.xml」以小'u'開頭。解決方案: - 兩個名稱應該相同。例如: - 「User.java」和「User.hbm.xml」。 - 快樂編碼。