0

I'm trying to apply a mysql specific function to a querydsl definition:

entity.departureDate.after(SQLExpressions.addDays(entity.departureDate, 10))

Results in generated sql:

select * from mytable where departureDate > add_days(departureDate,?1)

But that results in an exception, as add_days is not a known mysql function:

Caused by: java.sql.SQLSyntaxErrorException: FUNCTION mytable.add_days does not exist

Question: how can I tell querydsl to use DATE_ADD() function instead?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

0

The following solution works, but still feels kind of ugly. Please comment if there are better solutions than:

entity.departureDate.after(
        Expressions.dateTemplate(LocalDate.class,
                                 "FUNCTION('ADDDATE', {0}, {1})",
                                 entity.departureDate,
                                 10)));

This solution can also be found at: https://stackoverflow.com/a/22988168/1194415

membersound
  • 81,582
  • 193
  • 585
  • 1,120