문제

I'm a bit confused about what is happening when I give a Grails dynamic finder the wrong type.

For instance, if I have class Foo

class Foo {
    //long id (implicit id is a long)
    Long barValue
}

And I do, Foo.findByIdAndBarValue('1', '2'), I get a result, but I am confused about what is going on here with the string values.

Is it passing these string values directly to the db (potentially ignoring valuable indices due to type mismatch) or is Grails automatically converting the types?

도움이 되었습니까?

해결책

When passing parameters to the dynamic finders on Grails domain classes the parameters are dynamically typed. This allows for automatic type conversion, by Groovy.

In your example, Groovy is seeing that the barValue is of type Long and is casting the String value to a Long.

JN3015-Types explains this behavior of Groovy a bit further with some examples.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top