When a custom function wraps a subquery that uses order by, the sql for the order by is messed up.
This is the HQL:
The custom function LIMIT as can be found in the attached testcase in class MyMySQLDialect applies a limit(second argument) to the subquery(first argument) and returns the result. The problem is, that the function gets a messed up subquery for MySQL. The same function works for other databases in the sense that the order by is not messed up.
By messed up I mean that the following is produced:
instead of the expected: