在休眠条件中使用总和
Using sum in hibernate criteria
如何在休眠条件中表达这个查询?
select SUM (tabla2.valor1)
from tabla1 INNER JOIN
tabla2 ON tabla1.ID = tabla2.ID
where tabla1.ID = 1
谢谢!
你可以使用 Projections
,比如
getSessionFactory() //this is the session factory, initialized with-> new Configuration().configure().buildSessionFactory()
.openSession()
.createCriteria(tabla1.class)
.createAlias("tabla2.id", "tab2", JoinType.INNER_JOIN)
.setProjection(Projections.sum("tab2.valor1"));
如何在休眠条件中表达这个查询?
select SUM (tabla2.valor1)
from tabla1 INNER JOIN
tabla2 ON tabla1.ID = tabla2.ID
where tabla1.ID = 1
谢谢!
你可以使用 Projections
,比如
getSessionFactory() //this is the session factory, initialized with-> new Configuration().configure().buildSessionFactory()
.openSession()
.createCriteria(tabla1.class)
.createAlias("tabla2.id", "tab2", JoinType.INNER_JOIN)
.setProjection(Projections.sum("tab2.valor1"));