1
I have two tables, Products and Itensvenda In the itensvenda table I have a FK of products.
I want to make the following query using Hibernate criteria.
select count(itensvenda.prdcodigo), produtos.prddescricao from itensvenda
inner join produtos on itensvenda.prdcodigo = produtos .prdcodigo
group by itensvenda.prdcodigo, produtos.prddescricao
the following code works?
Criteria c = session.createCriteria();
c.createAlias("prdcodigo", "prdcodigo");
c.setProjection(Projections.count("prdcodigo.prdcodigo"));
c.setProjection(Projections.property("prdcodigo.prddescricao"));
c.setProjection(Projections.groupProperty("prdcodigo.prdcodigo"));
c.setProjection(Projections.groupProperty("prdcodigo.prddescricao"));
return c.list();
Guilherme, can’t test your code? If you can enable the query log in your
DataSource
and see if it looks the same. InCriteria
you should not specify the table name and its attributes, but the class name and its fields (The JPA implementation you are using will translate from class to table). And the class isn’t missingProdutos
and theinner join
with theItensVenda
?– Wakim
The code I posted didn’t work. ?
– Guilherme Villaca