Assuming we have a query like this one where the end parenthesis does not have a matching start parenthesis:
The end parenthesis is discarded instead of throwing an exception:
Now, this can lead to very weird situations where any clause following the extra round bracket is simply discarded.
So, if you have an ORDER BY clause after the extra parenthesis:
The ORDER BY vanishes from the SQL statement:
You can find a replicating test case in hibernate-core: