在Hibernate中如何使用LIKE表达式进行caseinsensitive fitering。 在我的休眠文件中的相关条目休眠 - LIKE表达式适用于大小写不敏感
<filter name="applicantNameFilter" condition="first_name LIKE :nameFilter"/>
在Hibernate中如何使用LIKE表达式进行caseinsensitive fitering。 在我的休眠文件中的相关条目休眠 - LIKE表达式适用于大小写不敏感
<filter name="applicantNameFilter" condition="first_name LIKE :nameFilter"/>
试试这个
<filter name="applicantNameFilter" condition="first_name ILIKE :nameFilter"/>
或
<filter name="applicantNameFilter" condition="UPPER(first_name) LIKE UPPER(:nameFilter)"/>
仅供参考
使用ILIKE:
SELECT * FROM sometable WHERE textfield ILIKE 'value%';
使用正则表达式运算符(见在docs函数和操作符):
SELECT * FROM sometable WHERE textfield ~* 'value';
使用UPPER()或LOWER()比较之前更改的字段的情况下; 这种方法可以优于1)或2),因为这些功能可以 索引,因此如果你正在做一个“开头”或“精确匹配”搜索 您的查询可以被索引:
SELECT * FROM sometable WHERE UPPER(textfield) LIKE (UPPER('value') || '%');
如果大多数搜索结果都是在“ ”字段中的“字段中的任意位置”搜索,我建议您查看PostgreSQL中 中提供的两个“全文搜索”工具,其中一个位于您的源文件的/ contrib中,其次来自openFTS.org。
这是Java代码
用户准则为
Criteria criteria = getSession().createCriteria(Person.class);
criteria.add(Restrictions.ilike("first_name", first_name, MatchMode.ANYWHERE));
criteria.list();
你可以尝试使用的~*
代替LIKE
。前者不区分大小写的模式匹配(并且是特定于PostgreSQL的)。
欲了解更多信息,请参阅手册:http://www.postgresql.org/docs/9.1/static/functions-matching.html#FUNCTIONS-POSIX-TABLE
<滤波器名称= “applicantNameFilter” 条件= “first_name的:nameFilter”/>我试图与此。但没有奏效。 – 1355 2012-07-17 09:04:40
现在我收到以下错误消息。我的eclipse控制台.. 'this_.first_name this_.ILIKE? 和this_.short_list_flag =? 和user4_.user_id =? org.hibernate.exception.SQLGrammarException:无法执行查询.......导致:org.postgresql.util.PSQLException:错误:语法错误处于或接近“this_” 位置:3314' – 1355 2012-07-17 09:53:43
替换?与实际值,并尝试直接在postgres控制台执行此查询。 – 2012-07-17 09:55:19
我对hibernate很新。我不知道该把它放在哪里。你在哪里申请第三个选项 – 1355 2012-07-17 09:55:24