solvable
Finally, I found a place in the OpenJPA 2.2.1 source code that caused this wierd statement to be created.
The explanation is very interesting, even the cause of my problem is in my code, because I never expected OpenJPA to create such a statement.
This happens when you create an SQL expression as an empty "in-values" collection. For instance:
Collection<String> usernames = .... // dynamically created // (maybe by another query before) Path<String> username = userJoin.get(User_.username); Predicate usernamePredicate = username.in(usernames);
When the usernames collection is empty, you get the wierd SQL created by OpenJPA. Well, if the usernames collection is empty, the SQL-in expression will ever evaluate to false. I think that OpenJPA developers wanted to make life easier for the database optimizer by generating an SQL expression that would ever be evaluated as false in this case. Therefore they posted
CAST(1 AS INTEGER) <> CAST(1 AS INTEGER)
in the SQL statement.
So far I can understand what the purpose is, but why they cannot make life easier for our developers by generating SQLs that tell us why they always generated a false expression. For example, a statement can be much clearer if it gives people information about what is happening (hint). For instance:
WHERE 'user.username in(emptyCollection)' IS NOT NULL;
It will also always be false, but the developer can understand what the problem is.
source share