I have this repository:
@Repository
public interface UserRepository extends
JpaRepository<User, String>,
JpaSpecificationExecutor<User> {
@Query("select u from User u, UserRole ur " +
"where u.dep = ur.dep " +
"and u.allowed = 1")
List<User> getAllowed();
}
But I want to change the @Query
by a custom Spring Data Specification
, in order to call it like:
repository.findAll(new Allowed());
So I have added extends JpSpecificationExecutor<User>
to my repository and now I'm trying to create the Specification
implementation:
public class Allowed implements Specification<User> {
@Override
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
//??
}
}
How can I convert the query above to a Predicate? How can I perform the join with UserRole
entity?