1

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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
MaximeStor
  • 11
  • 2
  • I think i have to keep it because we'll need to add Role in the future, otherwise I would have make table such as Actor – MaximeStor Feb 06 '15 at 15:04
  • Essentially what you want then is private Map> roles; which is unfortunately not supported in JPA. As far as I can see you will need to map as a Set or whatever and transform to a Map> in memory once loaded. – Alan Hay Feb 06 '15 at 16:16
  • Okay so in order to keep this database design I have to drop JPA ? – MaximeStor Feb 06 '15 at 19:34

0 Answers0