【发布时间】:2014-02-19 20:23:59
【问题描述】:
我正在尝试运行查询以查找基于 3 个具有“或”条件的字段的条目。这是我的查询:
def results = Person.createCriteria().list(params) {
eq "skillset.id", original.skillset.id
or { eq "primarySkill.id", original.primarySkill.id }
or { eq "jobRole.id", original.jobRole.id }
not { eq "id", original.id }
order "name", "asc"
}
在 person 对象中,我关心的 3 个字段:skillset、primarySkill 和 jobRole,是另一个对象的实例。我想找到任何这些字段匹配的人,除了原始人。但是,休眠查询似乎是在进行“与”查询而不是“或”查询。我可以自己输入 SQL,但我想学习如何以时髦的方式进行操作。
这是hibernate生成的查询
select this_.id as id5_0_,
this_.version as version5_0_,
this_.account_id as account3_5_0_,
this_.band as band5_0_, t
his_.end_date as end5_5_0_,
this_.job_role_id as job6_5_0_,
this_.name as name5_0_,
this_.primary_skill_id as primary8_5_0_,
this_.professional_market_place as professi9_5_0_,
this_.project_delivery_manager_id as project10_5_0_,
this_.project_manager_id as project11_5_0_,
this_.project_name as project12_5_0_,
this_.rate as rate5_0_,
this_.resource_deployment_manager_id as resource14_5_0_,
this_.skillset_id as skillset15_5_0_,
this_.start_date as start16_5_0_,
this_.work_location as work17_5_0_
from person this_ where this_.skillset_id=?
and (this_.primary_skill_id=?)
and (this_.job_role_id=?)
order by this_.name asc limit ?
【问题讨论】:
标签: grails grails-orm criteria