我正在学习春季休眠zk堆栈,并做我的第一次crud后this tutorial 我把applicationContext.xml到webapp/WEB-INF和.hbm.xml资源/映射 但我不知道为什么我的HBM文件保持显示无法找到我的pojos。放置applicationcontext.xml和.hbm文件的位置?
在github上https://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" />
Company.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:
<?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>
UPDATE:
- 我有参考contact.hbm.xml过,我错过了把它放在这里。
- 通过“为什么我的HBM文件一直显示无法找到我的POJO”我的意思是,当我尝试构建应用程序,我不断收到的“
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呢? –
对不起,我已经更新了这个问题,以澄清你问的问题。 – Kossel