简体   繁体   English

如何在groovy / grails中为嵌套对象创建条件?

[英]How to create criteria in groovy/grails for nested object?

I need help on creating hibernate criteria for nested object. 我需要帮助创建嵌套对象的hibernate标准。 For example : 例如 :

class office{
    Integer id;
    OfficeDetails cmdData ;
}

class OfficeDetails {
    Integer id;
    Region region;

}

class Region {
    Integer id;
    Integer regionNum;
}

Now, from the service class ( officeService) I am trying to pull up all of the offices that matches a certain region as : 现在,从服务类(officeService)我试图将所有匹配特定区域的办公室拉出来:

List<Office> findAllByRegion( Integer regionNumber){
    def criteria =  {  eq ( 'cmdData.region.regionNum', regionNumber ) }
    def allOfficesInTheRegion =  Office.findAll(criteria)

    return allOfficesInTheRegion
}

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? 总是得到异常:“org.hibernate.QueryException:无法解析属性:”我需要找到正确的方法来为此查询创建条件。任何人都可以帮忙吗?

See "querying associations" under the criteria section of the user guide : 请参阅用户指南条件部分下的“查询关联”:

def criteria = {
  cmdData {
    region {
      eq('regionNum', regionNumber)
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM