2017-02-09 3 views
1

Ich bin neu beim Lernen Hibernate.Ich möchte zwei Tabellenspalten in einzelne Hibernate Mapping-Datei zuordnen.Wie man zwei Tabellen in einer einzelnen hbm Datei abbildet

Ich habe zwei Tabellen Beispiel und Beispiel.

Meine Probe Tisch haben 3 Spalten wie

->upc 
->product name 
->product url 

und mein Beispiel Tabelle mit 2 Spalten

-> price 
-> product name 

ich auf diese Weise versucht, aber es ist mir nicht working.Please helfen zu lösen mein Problem.

Vielen Dank.

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

Antwort

0

Sie sollten Example von Sample wie Referenz:

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

Angenommen, haben Sie dies in der Example hbm:

<property name="productName" type="string"> 
    <column name="product_name" not-null="true" /> 
</property> 
Verwandte Themen