PostgreSQL like + Hibernate problem

Posted by Marat_Galiev on Stack Overflow See other posts from Stack Overflow or by Marat_Galiev
Published on 2011-02-02T07:23:07Z Indexed on 2011/02/02 7:25 UTC
Read the original article Hit count: 263

Filed under:
|
|
|
|

Hi all. I want to do search in PostgreSQL for INTEGER based columns.

if (!sSearch.isEmpty()) {
        sSearch = sSearch.replaceAll("[^a-zA-Z0-9]", "_").toLowerCase();
        String[] search = sSearch.split(" ");
        sWhere = " ";
        for (NewsColumns column : NewsColumns.values()) {
            for (String s : search) {
                sWhere += "lower(" + column + "::TEXT) LIKE '%" + s + "%' OR ";
            }
        }
        sWhere = sWhere.substring(0,sWhere.length()-3);
    }

Ok, I want to convert INT value to String before search, with '::TEXT' expression. But after executing I'm getting:

org.hibernate.QueryException: Not all named parameters have been set: [:TEXT] [select * from  news  WHERE lower(ID::TEXT) LIKE '%5%' Exception.

Looks like hibernate parse my convert exp as parameter. Any help is appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate