I have UserClass which has a relationship with Roles:
@Entity
@Table(name="USERS")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("ROLE_ADMIN")
@DiscriminatorColumn (name="ROLENAME", discriminatorType= DiscriminatorType.STRING, length=20)
@DiscriminatorOptions(force = true)
public class User extends BaseEntity implements UserDetails {
@ManyToOne
@JoinColumn(name = "role_id", referencedColumnName="id")
@NotNull(message = "Il campo RUOLO è obbligatorio")
private Role role;
//others fields
//getter & setter
}
In UserDAO, i have insert / edit / delete ... function and also the one which gives me all users list:
@Override
@SuppressWarnings("unchecked")
public List<User> getUsers() {
return getCurrentSession().createQuery("from User").list();
}
Now my question: i would like to build another function which gives me all users who have one of the roles i pass to the function:
public List<User> getUsers(List<Role> roles)
How can i do this? do i have to pass a List of Ids, or it's good pass a List of Roles?
in both cases, how can i write the the WHERE condition?
Thanks