I have 3 entities named : "Movie", "Person" and "Role", a person has a certain role in a movie.
In my database, i have these 3 entities and to link them, a table : Cast(id_movie,id_person,id_role) all primary, because a person can be for example producer and actor.
So far in my entity Movie I wrote this to make the link :
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "distribution",
joinColumns = @JoinColumn(name = "id_movie"),
inverseJoinColumns = @JoinColumn(name = "id_role"))
@MapKeyJoinColumn(name = "id_pers")
private Map<Person,Role> list_cast = new HashMap<Person,Role>();
But of course it doesn't work because key in a map is unique. So list_cast[person] gives me the only the last role.