Hibernate case-insensitive utf-8/unicode collation that works on multiple DBMS
-
20-09-2019 - |
Question
I'm looking for Hibernate annotation or .hbm.xml that allows me to specify a table column as case-insensitive string working in unicode/utf-8/locale-independent manner that works on multiple database engines.
Is there any such thing?
So that I can do query using Restrictions.eq("column_name", "search_string")
efficiently.
Solution
No, there's no mapping or annotation like that. Your options are:
- Handle this by specifying appropriate collation at the database level.
- Use lower() function that's defined for majority of (all?) dialects.
- If you want to use Criteria only, use
Restrictions.ilike()
for case-insensitive comparison. It actually useslower()
internally.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow