Java JPA CriteriaBuilder或表达式无法正常工作
这是我的方法:Java JPA CriteriaBuilder或表达式无法正常工作,java,jpa,expression,Java,Jpa,Expression,这是我的方法: CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<EmployersList> criteriaQuery = builder.createQuery(EmployersList.class); Root<EmployersList> root = criteriaQuery.from(EmployersList.class); Expression&l
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<EmployersList> criteriaQuery = builder.createQuery(EmployersList.class);
Root<EmployersList> root = criteriaQuery.from(EmployersList.class);
Expression<String> orgPhoneNumberExp = root.get("orgphoneNumber");
Predicate orgPhoneNumberPredicate = orgPhoneNumberExp.in(phoneNumber);
Expression<String> accPhoneNumberExp = root.get("accphoneNumber");
Predicate accPhoneNumberPredicate = accPhoneNumberExp.in(phoneNumber);
Expression<String> orgStatusExp = root.get("orgphoneStatus");
Predicate orgStatusExpPredicate = builder.upper(orgStatusExp).in("SUSPECT", "FRAUD", "NEGATIVE");
Expression<String> accPhoneStatusExp = root.get("accphoneStatus");
Predicate accPhoneStatuPredicate = builder.upper(accPhoneStatusExp).in("SUSPECT", "FRAUD", "NEGATIVE");
Expression<Date> orgPhoneStatusExpDateExmp = root.get("orgphoneStatusExpdate");
Expression<Date> accPhoneStatusExpDateExmp = root.get("accphoneStatusExpdate");
Predicate orgPhoneStatusExpDatePredicate = builder.or(builder.greaterThanOrEqualTo(orgPhoneStatusExpDateExmp, new Date()), builder.isNull(orgPhoneStatusExpDateExmp));
Predicate accPhoneStatusExpDatePredicate = builder.or(builder.greaterThanOrEqualTo(accPhoneStatusExpDateExmp, new Date()), builder.isNull(accPhoneStatusExpDateExmp));
Expression<Boolean> orgExp = builder.and(orgPhoneNumberPredicate, builder.and(orgStatusExpPredicate, orgPhoneStatusExpDatePredicate)).as(Boolean.class);
Expression<Boolean> accExp = builder.and(accPhoneNumberPredicate, builder.and(accPhoneStatuPredicate, accPhoneStatusExpDatePredicate)).as(Boolean.class);
criteriaQuery.where(builder.or(orgExp, accExp));
List<EmployersList> result = entityManager.createQuery(criteriaQuery).getResultList();
但我想得到这样的东西:
where
(
employersl0_.ORGPHONE_NUMBER in (
?
)
and (
upper(employersl0_.ORGPHONE_STATUS) in (
? , ? , ?
)
)
and (
employersl0_.ORGPHONE_STATUS_EXPDATE>=?
or employersl0_.ORGPHONE_STATUS_EXPDATE is null
)
)
or (
employersl0_.ACCPHONE_NUMBER in (
?
)
and (
upper(employersl0_.ACCPHONE_STATUS) in (
? , ? , ?
)
)
and (
employersl0_.ACCPHONE_STATUS_EXPDATE>=?
or employersl0_.ACCPHONE_STATUS_EXPDATE is null
)
)
你能帮我解决这个问题吗?:)在这种情况下,你最多定义3个谓词。
请指定do和on ORGHONE电话号码、ORGHONE状态和ORGHONE状态EXPDATE。
在ACCPHONE\u号码、ACCPHONE\u状态和ACCPHONE\u状态EXPDATE上指定b do和。
在主日期a和b上指示c do或
where
(
employersl0_.ORGPHONE_NUMBER in (
?
)
and (
upper(employersl0_.ORGPHONE_STATUS) in (
? , ? , ?
)
)
and (
employersl0_.ORGPHONE_STATUS_EXPDATE>=?
or employersl0_.ORGPHONE_STATUS_EXPDATE is null
)
)
or (
employersl0_.ACCPHONE_NUMBER in (
?
)
and (
upper(employersl0_.ACCPHONE_STATUS) in (
? , ? , ?
)
)
and (
employersl0_.ACCPHONE_STATUS_EXPDATE>=?
or employersl0_.ACCPHONE_STATUS_EXPDATE is null
)
)