| Just checked with 5.0.6. No change. Debugging lead me to org.hibernate.internal.util.StringHelper where in public static String replace (line 175-179) there is a check if it's already in parenthesis, however the logic of the check seems wrong.
boolean encloseInParens =
actuallyReplace
&& encloseInParensIfNecessary
&& !( getLastNonWhitespaceCharacter( beforePlaceholder ) == '(' )
&& !( getFirstNonWhitespaceCharacter( afterPlaceholder ) == ')' );
If it has a closing parenthesis on the right it will set encloseInParens to false, even without having the opening one. I don't remember how the specific boolean logic law was called, but formulated it's something like this !a && !b == !(a || b). Essentially, I believe the problem could be solved by changing the condition to:
boolean encloseInParens =
actuallyReplace
&& encloseInParensIfNecessary
&& !( getLastNonWhitespaceCharacter( beforePlaceholder ) == '('
&& getFirstNonWhitespaceCharacter( afterPlaceholder ) == ')' );
I tested the change and it works for my queries, but it might break something for the cases where you've done workarounds. Such old workarounds might have to be removed. |