出现错误:使用 JPQL 在“,”附近预期条件的上下文中指定非布尔类型的表达式

问题描述 投票:0回答:2

我编写了以下 JPQL 查询。在查询中,多个值(男性、女性等)出现在列表中,如性别列表或其他列表。它在控制台中显示一个错误,例如“在需要条件的上下文中指定的非布尔类型的表达式,靠近','”,“。请帮助我。尝试了很多方法来解决。

查询:

@Query("""
            SELECT customer_receiver
            FROM SubsidyCustomerUserReceiverEntity customer_receiver
            WHERE customer_receiver.deleted = false
                AND (:isPovertyLineCheck IS NULL OR :isPovertyLineCheck = false OR customer_receiver.isEligible = :isPovertyLineCheck)
                AND (:incomeLowerLimit IS NULL OR :incomeUpperLimit IS NULL OR
                            customer_receiver.receiverGrossHouseholdIncomeAmount BETWEEN :incomeLowerLimit AND :incomeUpperLimit)
                AND (:ageLowerLimit IS NULL OR :ageUpperLimit IS NULL OR
                            customer_receiver.ageYear BETWEEN :ageLowerLimit AND :ageUpperLimit)
                AND ((:locationList) IS NULL OR customer_receiver.area IN (:locationList))
                AND ((:employmentTypeList) IS NULL OR customer_receiver.employmentType IN (:employmentTypeList))
                AND ((:occupationList) IS NULL OR customer_receiver.incomeSourceOrOccupationName IN (:occupationList))
                AND ((:genderList) IS NULL OR customer_receiver.gender IN (:genderList))
            """)
    List<SubsidyCustomerUserReceiverEntity> getEligibleCustomerReceiver(BigDecimal incomeLowerLimit,
            BigDecimal incomeUpperLimit, Integer ageLowerLimit, Integer ageUpperLimit, Boolean isPovertyLineCheck,
            List<String> locationList, List<EmploymentType> employmentTypeList, List<String> occupationList,
            List<String> genderList);

我尝试过调整查询。

java sql jpql
2个回答
0
投票

有两件事你必须检查。

  1. 您没有在查询中传递任何空值参数。
  2. 还要检查参数类型,例如 < customer_receiver.isEligible > 确保 isEligible 和所有其他参数类型相同。

0
投票

我已经使用 JpaSpecification 解决了这个问题。谢谢大家的回答。

© www.soinside.com 2019 - 2024. All rights reserved.