{"record":{"id":"31c28e07cfdcbb6f","repo":"quarkusio/quarkus","slug":"method-of-repository-repository-is-meant-to-31c28e","errorCode":null,"errorMessage":"${method} of Repository ${repository} is meant to be a count query and therefore doesn't support Pageable and Sort method parameters","messagePattern":"(.+?) of Repository (.+?) is meant to be a count query and therefore doesn't support Pageable and Sort method parameters","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/DerivedMethodsAdder.java","lineNumber":299,"sourceCode":"                        }\n\n                        DotName effectiveReturnTypeName = finalReturnType.kind() == Type.Kind.TYPE_VARIABLE ? DotNames.OBJECT\n                                : finalReturnType.name();\n\n                        generateFindQueryResultHandling(bc, panacheQuery, finalPageableParameterIndex, params,\n                                repositoryClassInfo, entityClassInfo, effectiveReturnTypeName, parseResult.getTopCount(),\n                                method.name(), customResultTypeName,\n                                entityClassInfo.name().toString(), elementTypeToCast);\n\n                    } else if (parseResult.getQueryType() == MethodNameParser.QueryType.COUNT) {\n                        if (!DotNames.PRIMITIVE_LONG.equals(returnType.name())\n                                && !DotNames.LONG.equals(returnType.name())) {\n                            throw new IllegalArgumentException(\n                                    method.name() + \" of Repository \" + repositoryClassInfo\n                                            + \" is meant to be a count query and can therefore only have a long return type\");\n                        }\n                        if ((finalSortParameterIndex != null) || finalPageableParameterIndex != null) {\n                            throw new IllegalArgumentException(\n                                    method.name() + \" of Repository \" + repositoryClassInfo\n                                            + \" is meant to be a count query and therefore doesn't \" +\n                                            \"support Pageable and Sort method parameters\");\n                        }\n\n                        // call JpaOperations.count()\n                        Expr count = bc.invokeVirtual(\n                                MethodDesc.of(AbstractManagedJpaOperations.class, \"count\", long.class,\n                                        Class.class, String.class, Object[].class),\n                                ops, entityClass,\n                                Const.of(parseResult.getQuery()), paramsArray);\n\n                        handleLongReturnValue(bc, count, returnType.name());\n\n                    } else if (parseResult.getQueryType() == MethodNameParser.QueryType.EXISTS) {\n                        if (!DotNames.PRIMITIVE_BOOLEAN.equals(returnType.name())\n                                && !DotNames.BOOLEAN.equals(returnType.name())) {\n                            throw new IllegalArgumentException(","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/DerivedMethodsAdder.java#L281-L317","documentation":"Derived count queries (methods named countBy...) produce a single scalar number, so pagination and sorting make no sense for them. The spring-data-jpa extension rejects any countBy method that declares a Sort or Pageable parameter, failing the build with this IllegalArgumentException.","triggerScenarios":"Declaring e.g. long countByLastName(String lastName, Pageable pageable) or long countByActive(boolean active, Sort sort) — a COUNT query type with finalSortParameterIndex != null or finalPageableParameterIndex != null.","commonSituations":"Uniformly adding Pageable to every repository method when introducing pagination; copy-paste from a find method that legitimately took Pageable; UI code that wants 'total count for a page' and passes the same Pageable to a count method.","solutions":["Remove the Pageable/Sort parameter from the countBy method","Use the Page repository API instead: a findAll(Pageable) returning Page already exposes getTotalElements/getTotalPages, so no separate pageable count is needed","Split into two methods: one pageable find plus a plain parameterless countBy for totals"],"exampleFix":"// before\nlong countByLastName(String lastName, Pageable pageable);\n\n// after\nlong countByLastName(String lastName);","handlingStrategy":"validation","validationCode":"// Ensure countBy methods take no Pageable/Sort\nfor (Method m : PersonRepository.class.getDeclaredMethods()) {\n    if (m.getName().startsWith(\"countBy\") && Arrays.stream(m.getParameterTypes())\n            .anyMatch(t -> Pageable.class.isAssignableFrom(t) || Sort.class.isAssignableFrom(t)))\n        throw new IllegalStateException(m.getName() + \" must not take Pageable/Sort\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Page<T> findAll(Pageable) for totals instead of paginated counts","Keep count methods parameterized only by filter criteria","Search for 'countBy(.*Pageable' patterns in CI before building"],"tags":["spring-data","jpa","quarkus","derived-query","build-time"],"backgroundTag":"unsupported-pagination-on-count-query","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}