NamedQuery

6 respostas
java
R

Olá pessoal. Alguém pode me ajudar com o código abaixo? Por que a consulta não está funcionando?

public List<Pedido> getPedidosByCliente(Integer idCliente) {

    Query query = em.createNamedQuery("consultaPedidosCliente");  
    query.setParameter("idCliente", idCliente);
    List<Pedido> resultado = query.getResultList();
    em.close();
    return resultado;
}

6 Respostas

P

Qual é a mensagem de erro ou resultado? Stacktrace? Qual é a query consultaPedidosCliente?

R

Este é o resultado:

Results :

Tests in error:
testQuery(br.com.disruptiva.provabackend.business.TesteQuery): You have attempted to set a parameter value using a name of id that does not exist in the query string

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0


BUILD FAILURE

Total time: 5.624s
Finished at: Sat Dec 19 13:13:28 BRST 2015
Final Memory: 7M/164M

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-cli) on project provabackend: There are test failures.

Please refer to E:\Mario\docs_D\prova-dev-backend-dpt\target\surefire-reports for the individual test results.
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

P

Tens aqui o teu problema…

R

Esta é a query:




O que eu devo fazer?

I

Não seria “Query query = em.createNamedQuery(“Pedido.consultaPedidosCliente”);”?

L

acho q faltou vc acessar a propriedade id do Cliente.

select p from Pedido p join fetch p.itensPedido where p.cliente.id = :idCliente

Criado 19 de dezembro de 2015
Ultima resposta 7 de jan. de 2016
Respostas 6
Participantes 5