JPQL 自定义查询
JQPL Custom Query
我在 class 中有这个 Spring JPA 应用程序,我正在尝试弄清楚如何让自定义查询工作。我有 3 tables 设置关系(UserAccess -> Profiles -> Projects)。我的代码确实有效,但它为我提供了 table 中的所有项目。不是我试图通过他们的 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);
}
查询的最后一位应该是SELECT u.userAccessId FROM UserAccess AS u WHERE u.userId = :userID
吗?
我在 class 中有这个 Spring JPA 应用程序,我正在尝试弄清楚如何让自定义查询工作。我有 3 tables 设置关系(UserAccess -> Profiles -> Projects)。我的代码确实有效,但它为我提供了 table 中的所有项目。不是我试图通过他们的 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);
}
查询的最后一位应该是SELECT u.userAccessId FROM UserAccess AS u WHERE u.userId = :userID
吗?