views:

74

answers:

1

I got a table with a PK and a value "country", all my labels are definied in another table which has composite-ids.

Does anyone has an example for me how I can map my country value to the correct label in the other table?

mappings are bound on PK, if I'm not wrong.

  <class name="hibernate.P1" table="P1">

    <id name="id" type="int">
        <column name="LFNR" precision="7" scale="0" />
    </id>
    <property name="land" type="int" not-null="true">
        <column name="LAND" precision="1" scale="0" />
    </property>

<class name="hibernate.P5" table="P5">

    <composite-id name="Id" class="hibernate.P5Id">
        <key-property name="tab" type="string">
            <column name="TAB" length="4" />
        </key-property>
        <key-property name="lfnr" type="string">
            <column name="LFNR" length="4" />
        </key-property>
        <key-property name="usa" type="string">
            <column name="USA" length="4" />
        </key-property>
        <key-property name="hier" type="int">
            <column name="HIER" precision="2" scale="0" />
     </key-property>
     <key-property name="land" type="int">
            <column name="LAND" precision="3" scale="0" />
        </key-property>
     <key-property name="sart" type="string">
            <column name="SART" length="3" />
     </key-property>
    </composite-id>
    <property name="label" type="string">
      <column name="LABEL" length="50" />
    </property>


    .....

I can't change the layout of the db sadly.

A: 

Since you cannot guarantee that the only one row will be in the P5 table for a given row in P1, you should include a one-to-many, i.e. a set in P1 that itself contains one element of P5.

bertolami