{"record":{"id":"cbc5eb608c3ac2c0","repo":"quarkusio/quarkus","slug":"operation-cannot-be-specified-for-field-fieldp","errorCode":null,"errorMessage":"${operation} cannot be specified for field${fieldPath} because it is not a String type. Offending method is ${repositoryMethodDescription}.","messagePattern":"(.+?) cannot be specified for field(.+?) because it is not a String type\\. Offending method is (.+?)\\.","errorType":"exception","errorClass":"UnableToParseMethodException","httpStatus":null,"severity":"error","filePath":"extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/MethodNameParser.java","lineNumber":611,"sourceCode":"            return false;\n        }\n\n        // Check if the operator is at the beginning or preceded by capital letter.\n        boolean startsCorrectly = (index == 0) || Character.isLowerCase(str.charAt(index - 1));\n\n        // Check if the operator ends before the end or is followed by a capital letter.\n        boolean endsCorrectly = (index + operatorStr.length() == str.length())\n                || Character.isUpperCase(str.charAt(index + operatorStr.length()));\n\n        return startsCorrectly && endsCorrectly;\n\n    }\n\n    private void validateFieldWithOperation(String operation, FieldInfo fieldInfo, String fieldPath,\n            String repositoryMethodDescription) {\n        DotName fieldTypeDotName = fieldInfo.type().name();\n        if (STRING_LIKE_OPERATIONS.contains(operation) && !DotNames.STRING.equals(fieldTypeDotName)) {\n            throw new UnableToParseMethodException(\n                    operation + \" cannot be specified for field\" + fieldPath + \" because it is not a String type. \"\n                            + \"Offending method is \" + repositoryMethodDescription + \".\");\n        }\n\n        if (BOOLEAN_OPERATIONS.contains(operation) && !DotNames.BOOLEAN.equals(fieldTypeDotName)\n                && !DotNames.PRIMITIVE_BOOLEAN.equals(fieldTypeDotName)) {\n            throw new UnableToParseMethodException(\n                    operation + \" cannot be specified for field\" + fieldPath + \" because it is not a boolean type. \"\n                            + \"Offending method is \" + repositoryMethodDescription + \".\");\n        }\n    }\n\n    private QueryType getType(String methodName) {\n        if (methodName.startsWith(\"find\") || methodName.startsWith(\"query\") || methodName.startsWith(\"read\")\n                || methodName.startsWith(\"get\")) {\n            return QueryType.SELECT;\n        }\n        if (methodName.startsWith(\"count\")) {","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/MethodNameParser.java#L593-L629","documentation":"A string-only derived query operation (Like, Contains, StartsWith, EndsWith, NotLike, etc. — STRING_LIKE_OPERATIONS) was applied to a field whose type is not String. The parser rejects this at build time with UnableToParseMethodException.","triggerScenarios":"Methods like findByAgeLike(String pattern), findByNameContains on a numeric/date/binary field; any operation in STRING_LIKE_OPERATIONS whose resolved FieldInfo type is not DotNames.STRING.","commonSituations":"Pattern-matching queries written against numeric columns; copy-pasting string query method patterns to non-string fields; schema type changes from String to numeric after migration.","solutions":["Use an equality/range operation appropriate to the field type instead of Like/Contains/StartsWith/EndsWith","Convert the field to String if pattern matching is genuinely needed","Cast or map the value in JPQL via @Query, e.g. CAST(age AS string) LIKE ..."],"exampleFix":"// before (age is Integer)\nList<User> findByAgeLike(String pattern);\n// after\nList<User> findByAgeGreaterThan(int age);","handlingStrategy":"validation","validationCode":"// Only use Like/Contains/StartsWith/EndsWith on String fields:\n// if (String.class != field.getType()) throw new IllegalArgumentException(\"String op on non-String field\");","typeGuard":null,"tryCatchPattern":"try {\n    parser.parse(methodName);\n} catch (UnableToParseMethodException e) {\n    // switch to a type-appropriate operator or use @Query with CAST\n    throw new IllegalStateException(\"String-only op misuse: \" + e.getMessage());\n}","preventionTips":["Reserve Like/Contains/StartsWith/EndsWith for String fields only","Re-check derived queries after changing a field's type in the entity","Prefer equality/range operations for numeric and date fields"],"tags":["jpa","spring-data","derived-query","type-mismatch"],"backgroundTag":"derived-query-type-mismatch","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}