Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate中的条件查询 选择reportcategory.categoryName, reportcategory.categoryId 从reportcategory作为reportcategory 其中reportcategory.categoryId=1_Hibernate_Criteria - Fatal编程技术网

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类的别名,并可以使用别名获取结果。我不确定是否遵循了这些条件,但我已经为您在问题中提到的内容编写了一个查询。