Erro ao realizar consuta "operator does not exist: integer = character varying"

2 respostas
S

Quando não seleciono o bairo a consulta dar certo, mais se eu selecionar da o erro acima.
Segue o codigo:

public List<Cliente> ListaClientePorNome(String nome) {

GeralDAO dao = new GeralDAO();
        Session session = dao.getSession();
        
    String sql_query = "where 1 = 1";
    HashMap&lt;String, String&gt; params_list = new HashMap();
    if (this.nome != null && !this.nome.trim().equals("")) {
        sql_query = sql_query.concat(" AND lower(u.nome) like lower(:nome) ");
        params_list.put("nome", "%" + nome + "%");

    }                                

      if (this.telefoneCel != null && !this.telefoneCel.trim().equals("")) {
        sql_query = sql_query.concat(" AND lower(u.telefoneCel) like lower(:telefoneCel) ");
        params_list.put("telefoneCel", "%" + telefoneCel + "%");
    }

     if (this.cpfCnpj != null && !this.cpfCnpj.trim().equals("")) {
        sql_query = sql_query.concat(" AND lower(u.cpfCnpj) like lower(:cpfCnpj) ");
        params_list.put("cpfCnpj", "%" + cpfCnpj + "%");
    }
  
    if (this.bairro != null && !this.bairro.trim().equals("")) {
        
        sql_query = sql_query.concat(" AND id_bairro=:bairro ");
        
        params_list.put("bairro", bairro);
        
    }


    Query q = session.createQuery("from Cliente u " + sql_query + "ORDER By lower(u.nome) asc");
  
   for (String param : params_list.keySet()) {
          q.setParameter(param, params_list.get(param));
  
    }

    List&lt;Cliente&gt; clientes = q.list();
    

    return clientes;

}

2 Respostas

B

Traduzindo o erro eu diria que você tenta comparar a Id do Bairro com o Nome do Bairro e como ID é inteiro e nome é varchar ele reclama…

S

Dei uma pesquisada esse erro so ocorre apartir do postgresql 8.3,
as versoes anteriores da certo, fiz o teste e deu certo instalei a postgresql 8.2.15
e ta funcionando perfeitamente.

Criado 26 de maio de 2010
Ultima resposta 27 de mai. de 2010
Respostas 2
Participantes 2