我有項目,這種結構:Hibernate映射當CFG文件和實體文件在不同的文件夾
當我試圖通過休眠訪問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>
只是一個快速的想法,你有沒有嘗試將src/main/resources/user中的hbm.xml放在一起 – jambriz 2013-05-02 19:23:14
這使事情變得更糟......如果我把它放在那裏,我得到'Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException:resource:./DBUser.hbm.xml not found' ...但是你是對的,那將是一個很好的習慣單獨的文件夾.. – Dworza 2013-05-02 19:33:59
在我聽起來像你有 ,而不是你的hibernate.cfg.xml上的 –
jambriz
2013-05-02 22:04:51