加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

春季-将applicationcontext.xml和.hbm文件放在哪里?

发布时间:2020-12-15 01:21:17 所属栏目:大数据 来源:网络整理
导读:我正在学习spring hibernate zk stack,并在this tutorial之后做我的第一个任务 我将applicationContext.xml放入webapp / WEB-INF,并将.hbm.xml放入资源/映射 但是我不知道为什么我的hbm文件不断显示找不到我的pojos. 在github https://github.com/kossel/fir

我正在学习spring hibernate zk stack,并在this tutorial之后做我的第一个任务
我将applicationContext.xml放入webapp / WEB-INF,并将.hbm.xml放入资源/映射
但是我不知道为什么我的hbm文件不断显示找不到我的pojos.

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

更新:

>我也参考contact.hbm.xml,我错过了把它放在这里.
>通过“为什么为什么我的hbm文件一直显示找不到我的pojos”,我的意思是,当我尝试构建该应用程序时,我一直收到以下错误:“由:org.hibernate.MappingException:找不到实体类:com.iknition. firstzk.beans.Contact“我已经多次更改了那些配置文件的位置,并且仍然遇到相同的错误.

最佳答案
我认为您必须像这样一对一地指定mappingLocations:

<property name="mappingLocations">
  <util:list>
    <value>hibernate/Company.hbm.xml</value>
    <value>hibernate/Contact.hbm.xml</value>
  </util:list>
</property>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读