【问题标题】:SQL to criteria using restrictions and projections使用限制和预测的 SQL 到标准
【发布时间】:2014-05-21 16:52:06
【问题描述】:

谁能帮我用休眠条件编写下面的 SQL。

Select * 
rom cart c
where c.sno = '00001234a'
  and c.createdtime = (
    select max(c.createdtime)
    from cart c
    where c.sno='00001234a'
  )

我尝试了下面的 sn-p。
但它返回 timestamp(createdtime) 而不是购物车对象。

Criteria cr=session.createCriteria(cart.class,'ct');
cr.add(Restrictions.eq('ct.sno','00001234a'));
cr.setProjection(Projection.max(ct.createdtime));
List li=cr.list();

【问题讨论】:

    标签: hibernate criteria


    【解决方案1】:

    提供的代码示例与

    相同

    从购物车 c 中选择 max(c.createdtime) 其中 c.sno='00001234a'

    要处理您提供的查询,您可以使用两个请求并根据第一个查询的结果构建“和 c.createdtime”限制。 或者使用createQuery 方法构建更复杂的查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多