How can I express this query in hibernate criteria??
select SUM (tabla2.valor1)
from tabla1 INNER JOIN
tabla2 ON tabla1.ID = tabla2.ID
where tabla1.ID = 1
Thanks!
You can use Projections
, something like
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"));