【问题标题】:Using sum in hibernate criteria在休眠条件中使用 sum
【发布时间】:2018-07-27 08:29:50
【问题描述】:

如何在休眠条件中表达这个查询??

select SUM (tabla2.valor1) 
  from tabla1 INNER JOIN 
       tabla2 ON tabla1.ID = tabla2.ID 
 where tabla1.ID = 1

谢谢!

【问题讨论】:

  • 你的实体是什么样的?

标签: java sql hibernate criteria hibernate-criteria


【解决方案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"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    相关资源
    最近更新 更多