【发布时间】:2021-11-14 14:11:43
【问题描述】:
我在我们的应用程序中使用 JPA-Hibernate,我正在处理如下查询:
@Query(
value = "ReportDTO(report) FROM Report report " +
"JOIN p.clientFile cf " +
"JOIN cf.client cl " +
"WHERE report.active = TRUE " +
"AND :companyKey = CASE WHEN report.companyKey IS NOT NULL " +
"THEN report.companyKey " +
"ELSE cl.companyKey " +
"END " +
"ORDER BY report.publishedDate DESC",
countQuery = “..”
)
@NonNull
Page<TagReportDTO> findAll(@NonNull Pageable pageable, @Param("companyKey") String companyKey);
当 "companyKey" 是 single 值时,它起作用了。现在,我需要更改此 findAll 方法以接受公司密钥列表。所以它应该像(更改后):
@NonNull
Page<TagReportDTO> findAll(@NonNull Pageable pageable, @Param("companyKeys") List<String> companyKeys);
现在我很难在查询中容纳 对象列表或 companyKeys(而不是 :companyKey) case 语句将适用于列表中的每个项目。有什么方法可以循环吗?
【问题讨论】:
标签: java jpa spring-data-jpa jpql