Case-insensitive equals using Hibernate Criteria

后端 未结 7 1477
旧时难觅i
旧时难觅i 2021-01-31 13:32

I\'ve seen Restrictions.ilike(\'property\', \'%value%\'), but would like to generate SQL like: lower(property) = \'value\'. Any ideas?

I used:

Restri         


        
7条回答
  •  一向
    一向 (楼主)
    2021-01-31 14:26

    Be careful of using ilike because it would allow someone to enter things like "test%" and match. I use the following to do a case-insensitive equal in one app:

    ...
    Criteria crit=session.createCriteria(Event.class);
    crit.add(Expression.eq("rsvpCode","test1").ignoreCase());
    ...
    

提交回复
热议问题