0

The following query returns rows whose DOC_NAME column values contain a percent sign

SELECT * FROM DOCUMENT sd WHERE DOC_NAME like lcase('%@%%') ESCAPE '@';

However I cannot force Hibernate to do the same.

I've already seen the question here: Hibernate criteria accepting %% value I have written the code suggested in the accepted answer but it doesn't seem to work with DB2. Here is an excerpt from the log:

...
where
        lcase(this_.DOC_NAME) like ?
...
2020-12-07 18:38:48,774 TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - %\%%

There is no ESCAPE clause. How can I force Hibernate to do it right?

ka3ak
  • 2,435
  • 2
  • 30
  • 57
  • According to [this SO question and answer](https://stackoverflow.com/questions/700648/escape-percentage-sign-db2-sql), your current query for detecting a percent is incorrect. Please check and try again. – Tim Biegeleisen Dec 07 '20 at 15:59
  • @TimBiegeleisen Yes. My initial query worked only for the values that ended with percent sign but not with those that contained it in the middle. I've corrected it. Thanks. But it doesn't affect the Hibernate related part. – ka3ak Dec 07 '20 at 16:03

1 Answers1

0

You have to implement a custom Criterion like outlined in the SO answer or even better, switch to the JPA Criteria API as the Hibernate native Criteria API is deprecated and will be removed in the future. The replacement is the JPA Criteria API + Hibernate extensions.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58