2014-02-19 37 views
0

我想運行一個查詢,基於與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" 
    } 

在人對象,我關心的3個領域:skillset,primarySkill和jobRole,都是另一個對象的實例,我想找到任何一個匹配任何字段的人,除了原始的人。要做一個「和」查詢,而不是「或」查詢,我可以自己輸入SQL,但我想學習如何做到這一點groovy的方式。由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 ? 

回答

3

我相信ated應該

def results = Person.createCriteria().list(params) { 
    or { 
     eq "skillset.id", original.skillset.id 
     eq "primarySkill.id", original.primarySkill.id 
     eq "jobRole.id", original.jobRole.id 
    } 
    not { eq "id", original.id } 
    order "name", "asc" 
} 
相關問題