The following expression is parsed with wrong arguments count:
from MyEntity a
order by cast( REGEXP_REPLACE('0' || COALESCE( a.stringField ,'0'), '
+', '', 'g') as integer)
The cast() parsed arguments should be REGEXP_REPLACE(...) and integer, but the debugger says the parsed arguments are 5:
1- REGEXP_REPLACE(('0'||coalesce(familia1_.endereco_numero, '0'))
Notice that the fourth argument was parsed with the ) token, which is probably what is causing the issue.
The resulting error is a QueryException("cast() requires two arguments") being raised in CastFunction.java