1
I am trying to return a group query together with the product entity by returning all the data from the product table and the sum of the quantity. I get a mistake which is this:
Exception in thread "main" java.lang.IllegalArgumentException: Type specified for TypedQuery [br.com.previsao.model.Produto] is incompatible with query return type [class java.lang.Long]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.resultClassChecking(AbstractEntityManagerImpl.java:387)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:344)
at Teste.main(Teste.java:30)
The query code is as follows:
String jpql1 = "select p, sum(p.quantidadeRecente) from Produto p where p.gerenteFilial.chefe.codigo =:codigo";
//
// metodo buscarPorPaginacao
TypedQuery<Produto> query = manager.createQuery(jpql1, Produto.class);
query.setParameter("codigo", 3L);
List<Produto> produtos = query.getResultList();
for (Produto prod : produtos) {
System.out.println(" Impressão Produto da Empresa: ");
System.out.println(" Nome : " + prod.getDescricao() + "Valor" + prod.getValor() +"Gerente" +prod.getGerenteFilial().getChefe().getCodigo()
+ "Quantidade" + prod.getQuantidadeRecente()+ "Filial" + prod.getGerenteFilial().getNome());
}
I am using java 7. has this function?
– user2509556
@user2509556 Done
– Victor Stafusa
added java 8 to the project and worked . You can memo with a calculated product field.getValue * quantityRecent values ?
– user2509556
@user2509556 If all the products on the list have the same value, yes. However, if the values can vary, then there is no escape other than adding up all of them.
– Victor Stafusa
I saw that I cannot do this solution because I want to put it in a list see https://answall.com/questions/215761/help-com-tela-search
– user2509556