Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I join on two columns in the hibernate mapping file using the <join> tag?

I need to map a single class to two tables (both with multiple columns primary key). Let's say TABLE1 has id1,id2,id3 and TABLE2 has id1,id2 as primary keys. Now when writing the mapping file I would do something like the following:

<hibernate-mapping package="beans">
  <class name="TABLE1Class" table="TABLE1">
    <composite-id name="table1PK" class="TABLE1PKClass">
        <key-many-to-one name="id1" class="ID1Class" column="id1"/>
        <key-many-to-one name="id2" class="ID2Class" column="id2"/>
        <key-many-to-one name="id3" class="ID3Class" column="id3"/>
    </composite-id>
    <property name="someProperty" type="integer" not-null="true" column="x"/>
    <join table="TABLE2">
        <key column="id1" />
        <!-- <key column="id2"/> The join tag accepts only one key tag!!! 
How do I map the second key??? -->
        <property name="propertyFromTable2" type="float" not-null="true"/>
    </join>
  </class>
</hibernate-mapping>

As you can see the join tag accepts only one key tag! How do I map the second id?

Kind Regards,
Despot
P.S.: Merry Christmas and a Happy and Productive New Year ;)

like image 640
despot Avatar asked Dec 30 '10 17:12

despot


1 Answers

<key> may contain multiple <column> elements:

<key>
    <column name = "id1" />
    <column name = "id2" />
    <column name = "id3" />
</key>
like image 76
axtavt Avatar answered Oct 21 '22 04:10

axtavt