灵活的搜索查询适用于 hac,但不适用于 Java 代码
Flexible search query works on hac, but not on Java code
我创建了一个新的 ItemType (SalesData),并尝试通过程序执行一个简单的查询,但没有返回任何结果。在调试时,我复制了查询和关联的查询参数并在 hac 上执行,该查询返回了结果。为什么这个查询不能通过程序工作?基本上问题出在 fromDate 和 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);
}
尝试使用 Date
而不是 Timestamp
。
我创建了一个新的 ItemType (SalesData),并尝试通过程序执行一个简单的查询,但没有返回任何结果。在调试时,我复制了查询和关联的查询参数并在 hac 上执行,该查询返回了结果。为什么这个查询不能通过程序工作?基本上问题出在 fromDate 和 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);
}
尝试使用 Date
而不是 Timestamp
。