hibernate jpa criteriabuilder ignore case queries

前端 未结 2 1109
栀梦
栀梦 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()+"%"));   
    
    0 讨论(0)
  • 2021-01-31 14:08

    There is a CriteriaBuilder.upper() method:

    personCriteriaQuery.where(criteriaBuilder.like(
        criteriaBuilder.upper(personRoot.get(Person_.description)), 
        "%"+filter.getDescription().toUpperCase()+"%"));
    
    0 讨论(0)
提交回复
热议问题