Ternary associations by R4R Team

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.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!