Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring applicationcontext.xml和.hbm文件放在哪里?_Spring_Hibernate_Zk - Fatal编程技术网

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

Spring applicationcontext.xml和.hbm文件放在哪里?,spring,hibernate,zk,Spring,Hibernate,Zk,我正在学习SpringHibernateZK堆栈,并在下面做我的第一个crud 我将applicationContext.xml放入webapp/WEB-INF,将.hbm.xml放入resources/mappings 但是我不知道为什么我的hbm文件一直显示,我找不到我的POJO 在github 我有这个结构 applicationContext.xml <bean id="sessionFactory" class="org.springframework.orm.hibern

我正在学习SpringHibernateZK堆栈,并在下面做我的第一个crud 我将applicationContext.xml放入webapp/WEB-INF,将.hbm.xml放入resources/mappings 但是我不知道为什么我的hbm文件一直显示,我找不到我的POJO

在github

我有这个结构

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文件一直显示找不到我的POJO”我的意思是,当我尝试构建应用程序时,我不断得到“
    ”错误,原因是: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>
      
      
      ...
      
      我认为您必须逐个指定映射位置,如:

      <property name="mappingLocations">
        <util:list>
          <value>hibernate/Company.hbm.xml</value>
          <value>hibernate/Contact.hbm.xml</value>
        </util:list>
      </property>
      
      
      hibernate/Company.hbm.xml
      hibernate/Contact.hbm.xml
      
      您能否扩展这一点:“为什么我的hbm文件一直显示找不到我的POJO”?你遇到了什么问题?另外,您只在
      hibernate.cfg.xml
      中引用了
      Company.hbm.xml
      。关于
      Contact.hbm.xml如何?抱歉,我已更新了问题以澄清您的问题。我一直在使用位置和配置应用程序上下文文件,但仍然遇到相同的错误。我已经更新了问题。我怀疑问题出在我的.hbm配置中。我尝试了注释并成功了,然后我改成了你的建议并成功了!:杜克。查看LocalSessionFactoryBean的文档。它需要一个资源[]的数组。您不能将它们链接到*.hbm.xml.Annotations是不正确的,因为您已经在pom.xml中为Java 1.4配置了project。您是正确的,我将其更改为jdk 1.6。但是对于每一个配置路径,我必须在前面加上“classpath:”这个词,以便使它们工作,即使它们都在资源文件夹中。ej。我必须输入'classpath:hibernate/Contact.hbm.xml',否则它将无法编译,因为找不到文件例外如果您使用'mappingResources'属性,您是正确的,但如果我相信'mappingLocations'允许使用通配符表示法。