I have two tables, Products and Sales Items In the sales items table I have an FK of products.
I want to 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
Does the following code work?
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();