Error parsing cast() arguments

Description

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'))
2- '

+'
3- ''
4- 'g')
5- integer

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

Environment

Hibernate 4.3.5.5
Postgree

Assignee

Unassigned

Reporter

Clessio Mendes

Labels

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Critical
Configure