3

私は春の休止状態のzkスタックを学習しており、このチュートリアル に続いて最初のクラッドを実行しています。applicationContext.xmlをwebapp / WEB-INFに配置し、.hbm.xmlをリソース/マッピングに配置しています。私のpojoを見つけてください。

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ファイルが表示され続ける理由でpojoが見つからない」つまり、アプリケーションをビルドしようとすると、「Caused by: org.hibernate.MappingException: entity class not found: com.iknition.firstzk.beans.Contact」というエラーが発生し続けます。これらの構成ファイルの場所を何度も変更しても、同じエラーが発生します。
4

2 に答える 2

2

うーん... 外部の 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>
于 2012-05-24T18:34:42.490 に答える
1

次のように、mappingLocations を 1 つずつ指定する必要があると思います。

<property name="mappingLocations">
  <util:list>
    <value>hibernate/Company.hbm.xml</value>
    <value>hibernate/Contact.hbm.xml</value>
  </util:list>
</property>
于 2012-05-25T07:48:39.790 に答える