Cayenne SQLTemplate returning incorrect result

333 views Asked by At

I'm pretty stump on this issue. Please help.

sql = "SELECT * FROM scheduler_assignment a WHERE a.start < #bind($end)";
SQLTemplate query = new SQLTemplate(Assignment.class, sql);
query.setFetchingDataRows(true);
Map<String, Object> params = new HashMap<String, Object>();
params.put("end", end);
query.setParameters(params);
ObjectContext context = BaseContext.getThreadObjectContext();
List<DataRow> rows = context.performQuery(query);

end is a Date object. When I change end to its equivalent String, the query works correctly. Does anyone know why passing in the Date object would not work for the bind directive? Thank you!

1

There are 1 answers

3
andrus_a On BEST ANSWER

First possibility: 'scheduler_assignment.start' column is not a date in the database. It could be a VARCHAR or something.

If this is not the case, you may have to pass the type of the argument in the #bind directive for Cayenne to use the right driver method. E.g.:

#bind($end 'TIMESTAMP')