[英]Grails createCriteria from mysql query with inner join
I have this mysql query 我有这个mysql查询
SELECT cr1.project_id
FROM contribution_request as cr1
INNER JOIN contribution_request as cr2 ON cr1.project_id = cr2.project_id
WHERE cr1.instrument_id = 5 AND cr2.instrument_id = 6
And I need to execute it via grails createCriteria
function 我需要通过grails
createCriteria
函数执行它
I have tried this but it is not working and I cant find how to do it. 我试过这个,但它不起作用,我无法找到如何做到这一点。
def pc = ContributionRequest.createCriteria();
def Object = pc.list {
projections {
property("project.id")
}
and {
eq "instrument.id", 5L
eq "instrument.id", 6L
}
}
Thanks for your help 谢谢你的帮助
When you are using projections
you should use get
instead of list
. 当您使用
projections
您应该使用get
而不是list
。 Your code would looks like this: 您的代码如下所示:
def pc = ContributionRequest.createCriteria();
def Object = pc.get {
projections {
property("project.id")
}
and {
eq "instrument.id", 5L
eq "instrument.id", 6L
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.