IN parameter is not enclosed in parentheses

Description

We have a query with the following parts:

The second one that doesn't have any parentheses is generated properly

But the first part becomes

Currently the workaround is to add the parentheses, so I'm submitting this as minor priority, but it's my understanding that the JPA implementation is supposed to add them.

Note that this is in a Named Native Query. It might work in JPQL queries, but we don't use them, because it's much harder to develop and test them in pgAdmin

Activity

Show:

Yordan Gigov February 16, 2016 at 11:56 AM

I'm not so sure that checking just the left side will be correct for composite keys.
This query works under pgAdmin, but I haven't tested through Hibernate. I don't even know if I can give such parameters if they're not a composite primary key class. I'll get back to you on that, hopefully within 2 weeks. I have other things to do and it doesn't seem like a big priority.

Former user December 21, 2015 at 9:43 PM

Fixed in master and 5.0 branches.

Thanks for the tip about StringHelper. You were close. Hibernate should only check for a left parenthesis before the parameter to determine if it should be enclosed.

Yordan Gigov December 18, 2015 at 8:26 AM

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.

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:

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.

Former user December 18, 2015 at 1:11 AM

was fixed in 5.0.6. Please check to see if that fixes your issue.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created December 17, 2015 at 10:46 AM
Updated March 16, 2016 at 6:27 AM
Resolved December 21, 2015 at 9:43 PM