2017-02-09 11 views
1

hibernateを学習するのは初めてです.2つのテーブルの列を単一のハイバネートマッピングファイルにマップしたいと考えています。1つのhbmファイルに2つのテーブルをマップする方法

私は2つのテーブルを持っていますサンプル例。

マイサンプルの表は、

->upc 
->product name 
->product url 

と私の例の表のように3列は2列

-> price 
-> product name 

を持っている私は、この方法を試してみましたが、それは解決するために私を助けworking.Pleaseではありません私の問題。

ありがとうございます。

<class name="Trail" table="sample"> 

     <id name="upc" type="long"> 
     <column name="upc" /> 
     <generator class="identity" /> 
    </id> 
    <property name="ProductName" type="string"> 
     <column name="product name" not-null="true" /> 
    </property> 
    <property name="Producturl" type="string"> 
     <column name="producturl" not-null="true" /> 
    </property> 
    <join table="Example"> 
    <key column="productname"></key> 
    <property name="price" type="double" > 
     <column name="price"/> 
    </property> 
    </join> 

答えて

0

あなたが好きSampleからExampleを参照する必要がありますと仮定すると、

<many-to-one name="example" class="mypkg.Example" fetch="select" property-ref="productName"> 
     <column name="product_name" unique="true" /> 
</many-to-one> 

あなたはExample HBMでこれを持っている:

<property name="productName" type="string"> 
    <column name="product_name" not-null="true" /> 
</property> 
関連する問題