API / Apache Grails Interview questions
What is a dynamic finder in GORM?
A dynamic finder is a query method that looks like an ordinary static method call — Book.findByTitle("Dune") — but doesn't actually exist anywhere in source code; GORM generates its implementation at runtime by parsing the method name itself.
The pattern following findBy, findAllBy, or countBy is interpreted against the domain class's actual properties: findByTitleAndAuthor(title, author) builds a query filtering on both fields, findByTitleLike(pattern) uses a SQL LIKE clause, and comparison suffixes like GreaterThan or Between extend the same pattern to numeric and date ranges. GORM does this through Groovy's dynamic method dispatch (methodMissing/metaprogramming), inspecting the method name string at call time and translating it into the underlying query.
They're fast to write and read for simple lookups, but because the query logic lives entirely in a method name string rather than real code, a typo in a property name only fails at runtime, not at compile time — one of the reasons GORM Data Services exist as a more strictly-typed alternative for new code.
More Related questions...