382195 (2) [Avatar] Offline
#1
Hello,
I own the first edition of this book, and on pages 311-313 there are ternary associations described:
From a Category's perspective, this is an association that maps Items to Users:

@ManyToMany
@org.hibernate.annotations.MapKeyManyToMany(
joinColumns = @JoinColumn(name = "ITEM_ID")
)
@JoinTable(
name = "CATEGORY_ITEM",
joinColumns = @JoinColumn(name = "CATEGORY_ID"),
inverseJoinColumns = @JoinColumn(name = "USER_ID")
)
private Map<Item,User> itemsAndUser = new HashMap<Item,User>();



Now, you gave the reader an exercise to make it bidirectional.
I tried several ways but without luck.

Can you reveal us how it's done ?


Thanks a lot for a great book!

382195 (2) [Avatar] Offline
#2
In reality I have this problem - It's a many-to-many relationship between Zones and Access Groups and each Access Group has a time table by which it can access the Zone.
This is the mapping from the Access Group point of view:

    @ManyToMany
    @JoinTable( name = "access_group_zone", joinColumns = @JoinColumn( name = "access_group", nullable = false ) ,
            inverseJoinColumns = @JoinColumn( name = "timetable", nullable = true ) )
    @MapKeyJoinColumn( name = "zone" )
    @OrderBy
    private Map<Zone, Timetable> zones = new HashMap<Zone, Timetable>();


Now, how can this be mapped on the inverse side ?

Thanks