2013-05-02 70 views
0

我有項目,這種結構:Hibernate映射當CFG文件和實體文件在不同的文件夾

enter image description here

當我試圖通過休眠訪問DTB,我得到這個異常:

Initial SessionFactory creation failed.org.hibernate.MappingException: entity class not found: user/DBUser 
V 02, 2013 9:17:10 ODP. org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/fit] threw exception [Handler processing failed; nested exception is java.lang.ExceptionInInitializerError] with root cause 
java.lang.ClassNotFoundException: user/DBUser 

你能告訴我,我的配置文件中的路徑應該如何?我嘗試過幾種組合,但我無法弄清楚,如何編寫它。

DBUser.hbm.xml

<?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="DontKnowWhatShallBeHere/DBUser" table="DBUSER"> 
     <id name="userId" type="int"> 
      <column name="USER_ID" precision="5" scale="0" /> 
      <generator class="assigned" /> 
     </id> 
     <property name="username" type="string"> 
      <column name="USERNAME" length="20" not-null="true" /> 
     </property> 
     <property name="createdBy" type="string"> 
      <column name="CREATED_BY" length="20" not-null="true" /> 
     </property> 
     <property name="createdDate" type="date"> 
      <column name="CREATED_DATE" length="7" not-null="true" /> 
     </property> 
    </class> 
</hibernate-mapping> 

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.bytecode.use_reflection_optimizer">false</property> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">password</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3049/test</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="show_sql">true</property> 
     <mapping resource="DontKnowWhatShallBeHere/DBUser.hbm.xml"></mapping> 
    </session-factory> 
</hibernate-configuration> 
+0

只是一個快速的想法,你有沒有嘗試將src/main/resources/user中的hbm.xml放在一起 – jambriz 2013-05-02 19:23:14

+0

這使事情變得更糟......如果我把它放在那裏,我得到'Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException:resource:./DBUser.hbm.xml not found' ...但是你是對的,那將是一個很好的習慣單獨的文件夾.. – Dworza 2013-05-02 19:33:59

+1

在我聽起來像你有,而不是你的hibernate.cfg.xml上的 jambriz 2013-05-02 22:04:51

回答

1

一切看起來都沒有問題。你可以試試看: <class name="user.DBUser" table="DBUSER">

+0

I在想,如果那裏沒有問題,我正在使用'Spring 3安全性'。我嘗試了你的代碼,清理並構建了這個項目,但我仍然得到一些異常消息。在這裏的堆棧http://pastebin.com/VSM2m9yF – Dworza 2013-05-02 19:35:59

+0

Spring安全性如何與您在上述給定上下文中如何使用hibernate相關?嘗試以上併發回發生了什麼。 – happybuddha 2013-05-02 19:39:12

+0

我不知道......這只是一個猜測......我之前的評論已被編輯。 – Dworza 2013-05-02 19:41:07