2017-02-09 79 views
1

我是学习hibernate的新手。我想在单个hibernate映射文件中映射两个表列。如何在单个hbm文件中映射两个表

我有两个表样本例子。

样品表已经3列样

->upc 
->product name 
->product url 

和我的例子表有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>