As we are understanding with name of the topic Ternary association mapping that shows there is the three possible approaches to mapping a ternary association. One approach is use to a map with an association as its index.
Example of the Ternary association mapping:
@Entity
public class Computer {
@Id
int id;
...
@OneToMany // unidirectional
@MapKeyJoinColumn(name="part_id")
Map<Computer, Contract> contracts;
}
// or
<map name="contracts">
<key column="employer_id" not-null="true"/>
<map-key-many-to-many column="computer_id" class="Computer"/>
<one-to-many class="Contract"/>
</map>
In the ternary association we found the second approach is to remodel the assocation as a entity class. We need to remember this because this is very common approach. we can use as a final alternative is to use composite elements which will be dicussed.