I am trying to write a JPQL query that will work on Oracle, MySQL, or SQL Server. It's supposed to find all the items where a string field is not empty or null. On MySQL,
select x from Examples x where (x.foo != '' and x.foo IS NOT null)
works fine. However, due to the way Oracle converts empty strings to null, the != '' bit always returns false, so I get no results even if hardly any of the strings are empty. I could detect what kind of database the user is using and write a different thing for each, but it's not really nice to have three times as much JPQL. Is there any way of handling empty strings in JPQL that will work for Oracle as well?
I can find lots of related questions, like these:
null vs empty string in Oracle
Why does Oracle 9i treat an empty string as NULL?
https://dba.stackexchange.com/questions/49744/oracle-empty-string-converts-to-null
but nothing really about what to do about it, especially in JPQL. Anyone found a way around this?