hibernate jpa criteriabuilder ignore case queries

前端 未结 2 1131
栀梦
栀梦 2021-01-31 13:37

How to do a like ignore case query using criteria builder. For description property I want to do something like upper(description) like \'%xyz%\'

I have the

2条回答
  •  野性不改
    2021-01-31 14:07

    If the database contains German words with letters like Fußballschuhe in the column, java will modify the parameter in uppercase method to FUSSBALLSCHUHE and the query will not match. Lowercase will work in this case:

    personCriteriaQuery.where(criteriaBuilder.like(
        criteriaBuilder.lower(personRoot.get(Person_.description)), 
        "%"+filter.getDescription().toLowerCase()+"%"));   
    

提交回复
热议问题