【问题标题】:Criteria Query in HibernateHibernate 中的条件查询
【发布时间】:2015-01-11 10:38:02
【问题描述】:
SELECT reportcategory.categoryName, 
       reportcategory.categoryId 
FROM   reportcategory AS reportcategory 
WHERE  reportcategory.categoryId = 1

我想使用 Criteria 编写上述查询。 ReportCategory是我的pojo类和数据库中同名的表。

请帮帮我。

【问题讨论】:

    标签: hibernate criteria


    【解决方案1】:

    假设 Hibernate,这里是一个例子:

    List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.like("name", "Fritz%") )
    .add( Restrictions.between("weight", minWeight, maxWeight) )
    .list();
    

    更多详情请关注Criteria Queries

    您的案例的等效查询是:

    List result = sess.createCriteria(Reportcategory.class)
    .add( Restrictions.eq("categoryId", new Integer(1)) )
    .list();
    

    干杯!!

    【讨论】:

    • 我的问题是如何使用标准创建 pojo 类的别名,并可以使用别名获取结果
    • 不确定我是否关注过,但我已经为您在问题中提到的内容写了一个查询。
    猜你喜欢
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    相关资源
    最近更新 更多