Hibernate中的条件查询 选择reportcategory.categoryName, reportcategory.categoryId 从reportcategory作为reportcategory 其中reportcategory.categoryId=1
我想使用条件编写上面的查询Hibernate中的条件查询 选择reportcategory.categoryName, reportcategory.categoryId 从reportcategory作为reportcategory 其中reportcategory.categoryId=1,hibernate,criteria,Hibernate,Criteria,我想使用条件编写上面的查询ReportCategory是数据库中具有相同名称的pojo类和表 请在这方面帮助我。假设使用Hibernate,下面是一个示例: List cats = sess.createCriteria(Cat.class) .add( Restrictions.like("name", "Fritz%") ) .add( Restrictions.between("weight", minWeight, maxWeight) ) .list(); 更多详情见下文 您的案例的
ReportCategory
是数据库中具有相同名称的pojo类和表
请在这方面帮助我。假设使用Hibernate,下面是一个示例:
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.add( Restrictions.between("weight", minWeight, maxWeight) )
.list();
更多详情见下文
您的案例的等效查询为:
List result = sess.createCriteria(Reportcategory.class)
.add( Restrictions.eq("categoryId", new Integer(1)) )
.list();
干杯 我的问题是如何使用条件创建pojo类的别名,并可以使用别名获取结果。我不确定是否遵循了这些条件,但我已经为您在问题中提到的内容编写了一个查询。