I created a new ItemType (SalesData), and trying to execute a simple query via program, it's not returning any results. Where as while debugging, I copied the query and the associated query parameters and executed on hac, that query returned results. Why this query is not working via program? Basically the issue is with fromDate and toDate.
private static final String SALES_QUERY = "SELECT {"+ SalesDataModel.PK +"} FROM {"
+ SalesDataModel._TYPECODE + " AS F } "
+ "WHERE {F:" +SalesDataModel.PUBLISHED + "} = false "
+ "AND {F:" + SalesDataModel.TRANSACTIONDATE + "} >= ?fromDateTime "
+ "AND {F:" + SalesDataModel.TRANSACTIONDATE + "} < ?toDateTime ";
private static final String FROM_DATE_TIME = "fromDateTime";
private static final String TO_DATE_TIME = "toDateTime";
private void generateSalesFile(LocalDateTime yesterdayMidnight, LocalDateTime todayMidnight) {
FlexibleSearchQuery query = new FlexibleSearchQuery(SALES_QUERY);
query.addQueryParameter(FROM_DATE_TIME, java.sql.Timestamp.valueOf(yesterdayMidnight));
query.addQueryParameter(TO_DATE_TIME, java.sql.Timestamp.valueOf(todayMidnight));
final SearchResult<SalesDataModel> result = flexibleSearchService.search(query);
}
Try using Date
instead of Timestamp
.