我有这个Spring JPA应用程序,我正在上课,我正在试图弄清楚如何让自定义查询工作。我有3个表设置关系(UserAccess - >个人资料 - >项目)。我有这个代码可以工作,但它给了我表中的所有项目。不是我尝试通过userId执行的特定用户。我知道正常的SQL在这个问题上有效,但JPQL显然没有。任何帮助表示赞赏!
@Repository
public interface ProjectRepository extends CrudRepository<Project,Integer>{
/*
select * from Projects where profID =
(select profID from Profiles where userAccessID = 1);
*/
@Query("SELECT p FROM Project AS p WHERE p.profID = (SELECT p.profID FROM Profile AS f WHERE f.userAccessId = (SELECT u.userAccessId FROM UserAccess AS u WHERE u.userAccessId = :userID))")
public abstract List<Project> find(@Param("userID") int userID);
}
答案 0 :(得分:0)
查询的最后一位应该是SELECT u.userAccessId FROM UserAccess AS u WHERE u.userId = :userID
吗?