【发布时间】:2012-05-24 16:46:51
【问题描述】:
我正在学习 spring hibernate zk stack,并在 this tutorial 之后做我的第一个 crud 我将 applicationContext.xml 放入 webapp/WEB-INF,将 .hbm.xml 放入 resources/mappings 但我不知道为什么我的 hbm 文件一直显示找不到我的 pojos。
在githubhttps://github.com/kossel/firstzk
我有这个结构
applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- set other Hibernate properties in hibernate.cfg.xml file -->
<property name="configLocation" value="classpath:/com/iknition/firstzk/hibernate/hibernate.cfg.xml" />
</bean>
hibernate.cfg.xml
<mapping resource="com/iknition/firstzk/hibernate/Company.hbm.xml" />
<mapping resource="com/iknition/firstzk/hibernate/Contact.hbm.xml" />
公司.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 package="com.iknition.firstzk.beans">
<class name="Contact" table="contact">
<id name="idcontact" column="idcontact" type="integer">
<generator class="increment" />
</id>
<property name="name" column="name" type="string" />
<property name="email" column="email" type="string" />
<many-to-one name="company" column="companyId" class="com.iknition.firstzk.beans.Company" outer-join="true" />
</class>
</hibernate-mapping>
联系人.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 package="com.iknition.firstzk.beans">
<class name="Contact" table="contact">
<id name="idcontact" column="idcontact" type="integer">
<generator class="increment" />
</id>
<property name="name" column="name" type="string" />
<property name="email" column="email" type="string" />
<many-to-one name="company" column="companyId" class="com.iknition.firstzk.beans.Company" outer-join="true" />
</class>
</hibernate-mapping>
更新:
- 我也参考了contact.hbm.xml,没放在这里。
- “为什么我的 hbm 文件一直显示找不到我的 pojos”我的意思是,当我尝试构建应用程序时,我不断收到“
Caused by: org.hibernate.MappingException: entity class not found: com.iknition.firstzk.beans.Contact”的错误,我已经更改了很多次这些配置文件的位置,仍然得到同样的错误。
【问题讨论】:
-
你可以扩展这个:“为什么我的 hbm 文件一直显示找不到我的 pojos”?您遇到什么问题?此外,您仅在
hibernate.cfg.xml中引用Company.hbm.xml。Contact.hbm.xml呢? -
抱歉,我已更新问题以澄清您的问题。