Originally posted by Luigi Rubino: It's not clear how to configure a ternary association with Hibernate. Some help? Thanks, Luigi
Ternary Associations There are two possible approaches to mapping a ternary association. One approach is to use composite elements (discussed below). Another is to use a Map with an association as its index:
Originally posted by Ali Pope: What is the meaning of ternary association? (I couldn't figure it out from the reference :-( ).
Types of Associations 1. By type of verbs (Rumbaugh p. 156):
Associations often correspond to verbs. These include:
Physical Location (Next to, part of, contained in) Directed actions (drives) Communication (talks to) ownership (has, part of) Satisfaction of some condition (works for, married to, manages) 2. over one same object (i.e. Dancer IS NEXT TO Dancer) (Shlaer & Mellor p. 48)
3. Multiple relationships between two same objects. i.e., "Part IS OBTAINABLE FROM Supplier" "Part IS ON ORDER FROM Supplier"
4. The same object may participate in different relations that involve different objects. i.e., "Diskette WAS FORMATTED ON Disk Drive" "Diskette IS OWNED BY Person" "Diskette CONTAINS files"
5. Associations may also be: binary, ternary, or higher order. Binary associations involve two different classes. This is the most common. Higher order associations are more complicated to draw, implement, and think about than binary associations. [b]Ternary associations involve 3 objects:
It is an atomic unit The division of a ternary association into binary associations may loose information The associations are represented by a diamond + the name of the association Name of the association is optional
Joined: Jul 04, 2003
And more about Ternary Associations
Definition: Ternary associations are those that involve three first-rank classes. First-rank classes A, B and C are associated together in a relationship.
Scenario: We have first-rank classes Foo, Bar and Snafu which are all related together. We choose to store their relationship in Foo using a composite class BarSnafu:
Bar BarSnafu.getBar() // Retrieve Bar from BarSnafu Snafu BarSnafu.getSnafu() // Retrieve Snafu from BarSnafu Set Foo.getBarSnafus() // Retrieve set of BarSnafus from Foo
Hibernate Mapping: In Hibernate, this could be mapped as follows:
1. Foo id
2. Bar id
3. Snafu id
4. Foo_Bar_Snafu foo_id bar_id snafu_id
So here we've got three first-rank classes. They are related together in table foo_bar_snafu. The result is stored as a set of BarSnafu instances on each Foo. Each BarSnafu instance references one Bar and one Snafu.
NB: Using composite elements we can go beyond this and support 4 and more elements in a relationship.
Bidirectionality: Bidirectionality has no meaning for a ternary relationship.
Joined: Jul 12, 2004
Thanks for explanations/hints. Still I don't see how this is different from a normal relation :-(. ABC is related to A, B, and respectively C. Hmmm... seems in dunno get it [snif/].
Originally posted by Ali Pope: Thanks for explanations/hints. Still I don't see how this is different from a normal relation :-(. ABC is related to A, B, and respectively C. Hmmm... seems in dunno get it [snif/].
It's in fact a combination of multiple normal relations where the combination itself has to be represented as a relation.
Gian Franco Casula [ September 01, 2004: Message edited by: Gian Franco Casula ]
"Eppur si muove!"
Joined: Feb 26, 2004
Thanks to all. I'm new to Hibernate, and I like it very much. I think that the solution using an entity class is the most intuitive, and permits to manage all the attributes of the entity class.
Special thanks to Gavin for this great persistence framework.