2013-05-02 74 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