1

I'm facing a non usual issue while using criterias. I want to do a criteria with a like clause but the text contains special chars like the bracket char "[" and it seems that it's a special char in MSSQL database.

From an sql query I must use the special wording ESCAPE see example :

AND file1.FILE_NAME like '%[Main profile picture]%' **ESCAPE '['**

But I dont know how I can do the same using criteria. I'm currently using this clause temporarily :

criteria.add(Restrictions.like("files.fileName", "%Main profile picture%"));

but that's not what I want I really need to escape the '[' char.

Can somebody help me with this please...?

Thank you for your help!

michaPau
  • 1,598
  • 18
  • 24
Akyo
  • 139
  • 1
  • 12
  • Possible duplicate of [How can I escape square brackets in a LIKE clause?](http://stackoverflow.com/questions/439495/how-can-i-escape-square-brackets-in-a-like-clause) – Farside May 23 '16 at 10:09
  • Nope it cannot be a duplicate as it is not about the same technologies you have in one side sql query and the other is hibernate criteria. but thank you for this. – Akyo May 23 '16 at 12:53
  • it may be not fully a duplicate, but defines the concept of escaping chars within the LIKE clause, it's generic almost everywhere in SQL, so might hint the solution for you. – Farside May 23 '16 at 13:56

0 Answers0