applicationcontext.xml 和 .hbm 文件放在哪里?

2024-02-18

我正在学习 spring hibernate zk stack,并做我的第一个 crud 以下内容本教程 http://books.zkoss.org/wiki/Small_Talks/2011/December/Integrate_ZK5_with_Spring_3_and_Hibernate我将 applicationContext.xml 放入 webapp/WEB-INF 中,将 .hbm.xml 放入 resources/mappings 中 但我不知道为什么我的 hbm 文件一直显示找不到我的 pojos。

在 github 中https://github.com/kossel/firstzk https://github.com/kossel/firstzk

我有这个结构

应用程序上下文.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>

休眠配置文件

    <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>

UPDATE:

  • 我也参考了 contact.hbm.xml,我错过了把它放在这里。
  • by "为什么我的 hbm 文件一直显示找不到我的 pojo“我的意思是,当我尝试构建应用程序时,我不断收到错误”Caused by: org.hibernate.MappingException: entity class not found: com.iknition.firstzk.beans.Contact“我已经多次更改这些配置文件的位置,但仍然遇到相同的错误。

嗯...从未尝试过使用外部 hibernate.cfg.xml。但我认为指定仅加载属性。您可能仍需要在单独的属性中设置映射。

我的配置通常如下所示:

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
        <bean
            class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="propertiesArray">
                <list>
                    <props>...</props>
                </list>
            </property>
        </bean>
    </property>
    <property name="mappingLocations" value="classpath:com/iknition/firstzk/hibernate/*.hbm.xml"/>

</bean>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

applicationcontext.xml 和 .hbm 文件放在哪里? 的相关文章

随机推荐