如何在groovy / grails中为嵌套对象创建条件? [英] How to create criteria in groovy/grails for nested object?
本文介绍了如何在groovy / grails中为嵌套对象创建条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助创建嵌套对象的hibernate标准。例如:
I need help on creating hibernate criteria for nested object. For example :
class office{
Integer id;
OfficeDetails cmdData ;
}
class OfficeDetails {
Integer id;
Region region;
}
class Region {
Integer id;
Integer regionNum;
}
现在,我从服务类(officeService) :
Now, from the service class ( officeService) I am trying to pull up all of the offices that matches a certain region as :
List<Office> findAllByRegion( Integer regionNumber){
def criteria = { eq ( 'cmdData.region.regionNum', regionNumber ) }
def allOfficesInTheRegion = Office.findAll(criteria)
return allOfficesInTheRegion
}
总是收到异常:org.hibernate.QueryException:无法解析属性:
我需要找出正确的方式来为这个查询创建标准。任何人都可以帮忙吗?
Always getting exception :"org.hibernate.QueryException: could not resolve property:" I need to find out right way to create criteria for this query.Can anyone help?
推荐答案
根据用户指南的条件部分,查询关联:
See "querying associations" under the criteria section of the user guide:
def criteria = {
cmdData {
region {
eq('regionNum', regionNumber)
}
}
}
这篇关于如何在groovy / grails中为嵌套对象创建条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文