Difference in generated SQL between v5 and v6 for not equal ('<>') operator causes PostgreSQL query failure

I’m noticing a difference in the generated SQL for the ‘<>’ (not equal) operator between the 5.6.x series and the 6.x series while attempting to upgrade, and the difference appears to be causing PostgreSQL fits.

Sample JPA query: “select v from SampleEntity v where mycol <> -1” (where ‘mycol’ is an integer column).

In the 5.6.x series the generated SQL will look something like: “select * from sample where mycol<>-1” (notice that the query contains ‘<>’).

In the 6.x series, the generated SQL will look something like: “select * from sample where mycol!=-1” (notice that the query uses '!=" instead of expected ‘<>’)

The problem is that PostgresSQL will barf indicating that ‘!=-’ is not a valid operator. Wouldn’t be an issue if the generated SQL added whitespace around the ‘!=’, but since it doesn’t PostgresSQL is mis-interpreting the operator. The H2 DB I use in unit tests, appears to handle this case without issue.

Am I missing something? Is there a work-around or is this a real bug that somehow nobody else has noticed?

Have you tested with the latest Hibernate 6.x version? If the problem still persists, this looks like a bug to me. Please create a new entry in the issue tracker with a test case that reproduces the problem.

This looks like a bug so please create a JIRA issue for this with a test case that reproduces the problem. It should be easy to fix. Simply replace the String that is returned in org.hibernate.query.sqm.ComparisonOperator.NOT_EQUAL#sqlText

Thanks for taking a look. I’ve created [HHH-17234] - Hibernate JIRA for this issue (including test case :slight_smile: )

1 Like