4
I have a query native:
SELECT dist.nome Distrito,
    enti.nome Entidade,
    dist.id_distrito,
    dist.codigo_dne,
    dist.id_entidade,
    dist.id_municipio,
    dist.id_uf,
    dist.flag_ativo,
    muni.nome Municipio,
    unfe.nome UF
FROM glb.distritos  dist,
    glb.entidades  enti,
    glb.municipios muni,
    glb.ufs        unfe
WHERE dist.id_entidade  = enti.id_entidade
AND dist.id_municipio = muni.id_municipio
AND muni.id_uf        = unfe.id_uf
I tried to use in a JPA/Hibernate project using the annotation:
 ´nativeQuery=true´ 
And it didn’t work in the project, this error appeared in the log:
A nome da coluna nome não foi encontrado neste ResultSet.
But by running the query in the Postgres database it brings the information.
Error appears when I make a screen script request
$http({
            method : 'GET',
            url : 'http://localhost:8080/user/distritos'
        }).then(function(response) {
            $scope.distritos = response.data;
        }, function(response) {
            console.log(response.data);
            console.log(response.status);
        }); 
for the API In API I have the method
@RequestMapping(method = RequestMethod.GET, value = "/distritos", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Collection<Distritos>> buscarTodosDistritos() {
        Collection<Distritos> distritosBuscados = distritosService.buscarFiltro();
            return new ResponseEntity<>(distritosBuscados, HttpStatus.OK);
    } 
in the method distritosService.buscarFiltro(); 
@Query( nativeQuery=true,  value="SELECT dist.nome Distrito, dist.id_distrito, dist.id_entidade, dist.id_municipio, dist.id_uf, dist.codigo_dne, dist.flag_ativo,  enti.nome Entidade, muni.nome Municipio, unfe.nome UF FROM glb.distritos  dist, glb.entidades  enti, glb.municipios muni, glb.ufs unfe WHERE dist.id_entidade  = enti.id_entidade AND dist.id_municipio = muni.id_municipio AND muni.id_uf = unfe.id_uf ")
    public  Collection<Distritos>  buscarFiltro();
Could put the sector of the code it returns this error?
– Felipe Avelar
@Felipeavelar I edited the question..
– Eduardo Krakhecke
There really is no column
nomein theResultSet, since you’re using aliases for them:dist.nome Distrito,enti.nome Entidade, etc. Just to see this use onlydist.nome– Bruno César
@Brunocésar you were right. It worked. Posta como resposta.
– Eduardo Krakhecke