Когда собственный запрос конвертируется в HQL, он выдает непредвиденную ошибку узла AST
Я пытался описать ниже Условия в нативном запросе
if (grcLibraryReportRequest.getRptStartDate() != null) {
startdate = UtilityServices.convertStringToDate(grcLibraryReportRequest.getRptStartDate(),
AppConstants.DEFAULT_DATE_FORMAT_TIMESTAMP_GMT);
}
if (grcLibraryReportRequest.getRptEndDate() != null) {
enddate = UtilityServices.convertStringToDate(grcLibraryReportRequest.getRptEndDate(),
AppConstants.DEFAULT_DATE_FORMAT_TIMESTAMP_GMT);
}
StringBuilder sql = new StringBuilder(
"select riskplan, createdBy.userName, modifiedBy.userName, approvar1.userName, approvar2.userName from RiskPlan riskplan ");
sql.append("Left join User createdBy ON riskplan.createdBy=createdBy.id ");
sql.append("Left join User modifiedBy ON riskplan.modifiedBy=modifiedBy.id ");
sql.append("Left join User approvar1 ON riskplan.appLevel1=approvar1.id ");
sql.append("Left join User approvar2 ON riskplan.appLevel2=approvar2.id ");
sql.append("where ( riskplan.actionId = " + AppConstants.WORK_FLOW_RISK_APPROVER_2_STAGE
+ " or riskplan.actionId = " + AppConstants.WORK_FLOW_RISK_PLAN_REJECTED_STAGE + " ) ");
if (grcLibraryReportRequest.getRptStartDate() != null
&& grcLibraryReportRequest.getRptEndDate() != null) {
sql.append("AND CASE WHEN riskplan.validFrom IS NULL THEN (riskplan.modifiedOn <= '"
+ startdate + "') ELSE (riskplan.validFrom <= '" + enddate + "' AND riskplan.validUntil >= '"+startdate+"')END");
}
Query query = getEntityManager().createQuery(sql.toString());