'How to do ternary association is hibernate (java)?

I have 3 classes - MovieEntry, ActorEntry, CharacterEntry. An actor can be in multiple movies and play multiple characters (even in 1 movie) and a movie can have multiple actors and characters and a character can be in multiple movies.
When I pull a movie I want to know which actors are cast for it and what characters they play in that movie. Also when I pull an actor I want to know in which movies they play and what characters they play in every movie. I have:

@MappedSuperclass
public abstract class BaseEntity {
    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;

    //...
}
@Entity
@Table(name = "movies")
@Inheritance(strategy = InheritanceType.JOINED)
public class MovieEntry extends BaseEntry {
    @Column(nullable = false)
    private String title;

    //...
    @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "movies_cast",
            joinColumns = @JoinColumn(name = "movie_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "cast_id", referencedColumnName = "id"))
    private Set<ActorEntity> cast;
    //...
}

@Entity
@Table(name = "actors")
@Inheritance(strategy = InheritanceType.JOINED)
public class ActorEntry extends BaseEntry {
    @Column(nullable = false)
    private String name;

    //...
    @ManyToMany(mappedBy = "cast", fetch = FetchType.EAGER)
    private Set<MovieEntity> acting;
    //...
}
@Entity
@Table(name = "characters")
public class CharacterEntity extends BaseEntity {
    @Column(nullable = false)
    private String name;

    //...
}

So basically I want to associate an Actor that plays a Character in a Movie. Should I just create another class that combines the 3 entities (I've checked other questions and that is what is suggested there) or is there another (Hibernate specific maybe) way to do it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source