Reputation: 17497
I Have an Oracle DB that uses UTF-8. I am issuing some search queries, with like
predicates to filter by some name column.
Since the data in the table are French and German names, they might contain accentuated characters, such as àäèüéö
etc...
A like
predicate that is written in JPQL looks like this (I simplified to keep just the relevant part):
...where lower(convert(item.value, 'US7ASCII')) like lower(convert(CONCAT('%',:query,'%'), 'US7ASCII'))
That yields the following SQL once converted to the Oracle dialect :
lower(convert(items4_.SSI_ITEM, 'US7ASCII')) like lower(convert('%'||?||'%', 'US7ASCII'))
Both sides of the like
operator are converted to lower case and to the ?US7ASCII` character set, which removes accents. Note that both sides are converted by the database itself, using the same function. It makes the search "accent-insensitive", so to say.
Now, this works fine and is used for a relatively simple query, that returns names for the autocomplete of the field.
However, the main search query is way more complex and dynamic (lots of joins, dynamic criteria), and I am using QueryDSL to build it.
Is it possible to reproduce the above character conversion using QueryDSL over JPA ?
Upvotes: 1
Views: 1441
Reputation: 2931
Sorry to say that, but convert function is not JPA-compatible. It works for you just because hibernate interprets your JPQL as HQL. But QueryDSL supports only JPA standard (or you should use querydsl over hibernate). You have several options, as I see:
Looks like 2nd option is most easy to implement - just one pretty simple SQL migration, where you create additional column, insert normalized data there and create trigger for newly-added data to be automatically converted.
Upvotes: 2