在哪里放置applicationcontext.xml和.hbm文件? [英] where to put applicationcontext.xml and .hbm files?
问题描述
我正在学习spring hibernate zk stack,并在本教程
我将applicationContext.xml放入webapp / WEB-INF,并将.hbm.xml放入资源/映射中
但是我不知道为什么我的hbm文件一直显示无法找到我的pojos 。
在github中 https://github.com/ kossel / firstzk
我有这个结构
< bean id =sessionFactoryclass =org.springframework.orm.hibernate3.LocalSessionFactoryBean>
< property name =dataSourceref =dataSource/>
<! - 在hibernate.cfg.xml文件中设置其他Hibernate属性 - >
< property name =configLocationvalue =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映射DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\"> ;
< hibernate-mapping package =com.iknition.firstzk.beans>
< class name =Contacttable =contact>
< id name =idcontactcolumn =idcontacttype =integer>
< generator class =increment/>
< / id>
< property name =namecolumn =nametype =string/>
< property name =emailcolumn =emailtype =string/>
< / class>
< / hibernate-mapping>
Contact.hbm.xml:
<?xml version =1.0?>
<!DOCTYPE hibernate-mapping PUBLIC - // Hibernate / Hibernate映射DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\"> ;
< hibernate-mapping package =com.iknition.firstzk.beans>
< class name =Contacttable =contact>
< id name =idcontactcolumn =idcontacttype =integer>
< generator class =increment/>
< / id>
< property name =namecolumn =nametype =string/>
< property name =emailcolumn =emailtype =string/>
< / class>
< / hibernate-mapping>
更新:
的错误。引起:org.hibernate.MappingException:找不到实体类:com.iknition .firstzk.beans.Contact
我改变了很多次这些配置文件的位置,并且仍然出现相同的错误。
我认为您必须逐个指定mappingLocations:
< property name =mappingLocations>
< util:list>
< value> hibernate / Company.hbm.xml< /值>
< value> hibernate / Contact.hbm.xml< /值>
< / util:list>
< / property>
I'm learning spring hibernate zk stack, and doing my first crud following this tutorial I put applicationContext.xml into webapp/WEB-INF, and .hbm.xml to resources/mappings But I dont know why my hbm files keep showing can not find my pojos.
in github https://github.com/kossel/firstzk
I have this structure
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:
- I have reference to contact.hbm.xml too, I missed to put it here.
- by "why my hbm files keep showing can not find my pojos" I mean, when I try to build the application, I keep getting error of "
Caused by: org.hibernate.MappingException: entity class not found: com.iknition.firstzk.beans.Contact
" I have changed many times the location of those configuration files, and still getting same error.
I think you have to specify mappingLocations one-by-one like:
<property name="mappingLocations">
<util:list>
<value>hibernate/Company.hbm.xml</value>
<value>hibernate/Contact.hbm.xml</value>
</util:list>
</property>
这篇关于在哪里放置applicationcontext.xml和.hbm文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!