fabio.caimi
fabio.caimi

Reputation: 35

Join over the same table (using a non PK column)

I have a table which needs a relationship over itself.

Table Example:

field_PK ---> Primary key 
field_A ---> used as Foreign key to field_B 
field_B

Mapping:

  <id name="field_PK">
      <generator class="assigned"/>
  </id>

    ......

  <bag name="childs">
      <key column="field_A"  update="false"/>
      <one-to-many class="example"/>
  </bag>

 </class>
</hibernate-mapping>

I've noticed that by default NH uses the PK to perform joins... How can I tell NH to join field_A on field_B (instead of joining field_A on the PK)?

Upvotes: 0

Views: 213

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52745

You can use the property-ref attribute to join to any mapped property.

Upvotes: 1

Related Questions