Hibernate version:3.2.5.ga
Mysql 5.0:
Code:
Class Theme {
@CollectionOfElements(targetElement = TernaryAssociation.class, fetch = FetchType.LAZY)
@JoinTable(name = "themes_locations_types", joinColumns = @JoinColumn(name = "theme_id"))
public Set<TernaryAssociation> getAssociations() {
}
}
Class Location {}
Class Type {}
@Embeddable
Class TernaryAssociation {
@Parent
public Theme getTheme(){
}
@ManyToOne
@JoinColumn(name = "location_id", nullable = false, updatable = false)
public Location getLocation() {
}
@ManyToOne
@JoinColumn(name = "type_id", nullable = false, updatable = false)
public Type getType() {
}
}
Class A owns the relation.
First, is this the right way to have a ternary association?
Second, I am able to say A.getAssociations to get the list of associations but what I am looking for is give me C where a.id = 1 and b.id=1.
Theme
------------------------
| 1 | description 1
| 2 | description 2
| 3 | description 3
Location
------------------------
| 1 | description 1
| 2 | description 2
| 3 | description 3
Type
------------------------
| 1 | description 1
| 2 | description 2
| 3 | description 3
Theme_Location_Type
------------------------
| 1 | 1 | 1 |
| 2 | 1 | 1 |
| 3 | 1 | 1 |
| 1 | 2 | 1 |
| 2 | 2 | 1 |
| 3 | 2 | 1 |
How do I get, say 2 2 1 from Theme_Location_Type? I have a handle of Theme object. One way of doing it is get the list through theme object and loop until I find the right record.
Thanks