I resolve the problem making a bidirectional relationship between Actor and Role class:
public abstract class Actor{ @OneToMany(mappedBy="actor") List<Role> roles }
public class Person extends Actor {}
public class Organization extends Actor {}
public abstract class Role{ @ManyToOne @JoinColumn(name="ID_ACTOR") Actor actor }
public class Customer extends Role{}
public class Employee extends Role{}
That way I could get the List<role>
which plays a particular Actor:
public List<Role> getRoles(Actor actor) {
return actor.getRoles();
}
Initially I would like to avoid the bidirectional relationship, but I realized that in this particular case, there are direct benefits