그루비 버전 나는 같은 절을 사용하여 내 고문 테이블에서 행을 끌어 시도하고 2.5.1문제는/속한-에도 절
2.4.8 Grails의 버전 방법에 전달 된 회사 이름이 있으면 그 회사의 고문 만 끌어오고 싶습니다.
나는 잘 작동하는 기업 구성 요소가없는 두 개의 쿼리를 구성하지만 두 번째 쿼리 실행을 테스트하기 위해 회사를 설정하는 행의 주석을 해제하고 때 나는 아래의 예외가org.springframework.orm.hibernate4.HibernateQueryException: Not all named parameters have been set: [firm] [from Advisor a where lower(a.firstName) like:keystrokes OR lower(a.lastName) like:keystrokes AND a.firm.name = :firm];
코드 :
def getAdvisorsForKeystrokes(String keystrokes, String firm, int maxResults) {
List<Advisor> advisors;
firm = "Test Firm Name"
if(firm.allWhitespace) {
advisors = Advisor.findAll('from Advisor a where lower(a.firstName) like:keystrokes OR lower(a.lastName) like:keystrokes', [keystrokes:keystrokes + '%'], [max:maxResults])
} else {
advisors = Advisor.findAll('from Advisor a where lower(a.firstName) like:keystrokes OR lower(a.lastName) like:keystrokes AND a.firm.name = :firm', [keystrokes:keystrokes + '%'], [firm:firm], [max:maxResults])
}
return advisors
}
클래스 :
class Advisor {
String firstName
String lastName
String fullName
String city
String state
Firm firm
static belongsTo = [Case, Firm]
static hasMany = [cases:Case]
static constraints = {
}
}
class Firm {
String name
static constraints = {
}
}
,536,
어떤 사람이 문제가 무엇인지 아이디어가 있거나 놀라운 해결책이 있다면 고마워요!
편집 : 나는 아래 작업과 같이 다시 작성할 수 있습니다하지만 난 한 쿼리에서 그것을 할 수있는 여러 가지 방법을 시도하고 내가 그것을 작동시킬 수있는 방법을 찾을 수 없었던 것이 귀찮은 알고
.
def getAdvisorsForKeystrokes(String keystrokes, String firm, int maxResults) {
List<Advisor> advisors;
advisors = Advisor.findAll('from Advisor a where lower(a.firstName) like:keystrokes OR lower(a.lastName) like:keystrokes', [keystrokes:keystrokes + '%'], [max:maxResults])
if(!firm.allWhitespace) {
def firmModel = Firm.findByName(firm)
advisors = advisors.findAll{ adv ->
adv.firm == firmModel
}
}
return advisors
}
를하지만, 같은 맵에 모두 PARAMS 설정 시도? Advisors = Advisor.findAll ('Advisor에서 a.firstName과 같은 위치 : keystrokes 또는 a.lastName) : keystrokes 및 a.firm.name = : firm', [keystrokes : keystrokes + % ', firm : firm], [max : maxResults]) – Eylen
@Eylen Perfect! 왜 내가 각 매개 변수에 대해지도를 결정했는지 모르겠다. 아마도 예제와 패턴이 일치하는 새로운지도를 보았을 것이다. 감사!! – NewDev