2012-07-17 38 views

回答

3

試試這個

<filter name="applicantNameFilter" condition="first_name ILIKE :nameFilter"/> 

<filter name="applicantNameFilter" condition="UPPER(first_name) LIKE UPPER(:nameFilter)"/> 

僅供參考

  1. 使用ILIKE:

    SELECT * FROM sometable WHERE textfield ILIKE 'value%';
  2. 使用正則表達式運算符(見在docs函數和操作符):

    SELECT * FROM sometable WHERE textfield ~* 'value';
  3. 使用UPPER()或LOWER()比較之前更改的字段的情況下; 這種方法可以優於1)或2),因爲這些功能可以 索引,因此如果你正在做一個「開頭」或「精確匹配」搜索 您的查詢可以被索引:

    SELECT * FROM sometable WHERE UPPER(textfield) LIKE (UPPER('value') || '%');
  4. 如果大多數搜索結果都是在「 」字段中的「字段中的任意位置」搜索,我建議您查看PostgreSQL中 中提供的兩個「全文搜索」工具,其中一個位於您的源文件的/ contrib中,其次來自openFTS.org。

這是Java代碼

用戶準則爲

Criteria criteria = getSession().createCriteria(Person.class); 
criteria.add(Restrictions.ilike("first_name", first_name, MatchMode.ANYWHERE)); 
criteria.list(); 
+0

現在我收到以下錯誤消息。我的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

+0

替換?與實際值,並嘗試直接在postgres控制檯執行此查詢。 – 2012-07-17 09:55:19

+0

我對hibernate很新。我不知道該把它放在哪裏。你在哪裏申請第三個選項 – 1355 2012-07-17 09:55:24