I need to make a query in the database and return only the values based on the variable, my code returns the list with all the data of the city field, I want to return only the cities based on the state that the user select first. The state return (the variable that has to be inserted into the hlq) would be 'sgEstado'
public List<FilialComplementoTO> findCidadesByDsCidade() throws IntegrationException {
List cidades;
List<FilialComplementoTO> listOk ;
try {
Session session = InitSessionFactory.getInstance().getCurrentSession();
StringBuffer hql = new StringBuffer();
hql.append(" select g.dsCidade from FilialComplementoTO g ");
hql.append(" group by g.dsCidade ");
Query objQuery = session.createQuery(hql.toString());
cidades = (List) objQuery.list();
listOk = new ArrayList<FilialComplementoTO>();
for(Object obj: cidades){
FilialComplementoTO comple = new FilialComplementoTO();
comple.setDsCidade(obj.toString());
listOk.add(comple);
}
System.out.println(cidades);
} catch (Exception e) {
Logger.getLogger(this.getClass().getName()).error(e.getMessage());
throw new IntegrationException(e);
}
return listOk;
}