quarkusio/quarkus · error · IllegalArgumentException

${method} of Repository ${repository} is meant to be a delet

Error message

${method} of Repository ${repository} is meant to be a delete query and therefore doesn't support Pageable and Sort method parameters

What it means

Derived delete operations (deleteBy...) act on all matching rows at once, so Sort and Pageable parameters are meaningless for them. The spring-data-jpa extension rejects any deleteBy method declaring a Sort or Pageable parameter. The message text says 'count query' because the DELETE branch reuses the same message string — it is still thrown from the DELETE code path.

Source

Thrown at extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/DerivedMethodsAdder.java:345

                        // call JpaOperations.exists()
                        Expr exists = bc.invokeVirtual(
                                MethodDesc.of(AbstractManagedJpaOperations.class, "exists", boolean.class,
                                        Class.class, String.class, Object[].class),
                                ops, entityClass,
                                Const.of(parseResult.getQuery()), paramsArray);

                        handleBooleanReturnValue(bc, exists, returnType.name());

                    } else if (parseResult.getQueryType() == MethodNameParser.QueryType.DELETE) {
                        if (!DotNames.PRIMITIVE_LONG.equals(returnType.name()) && !DotNames.LONG.equals(returnType.name())
                                && !DotNames.VOID.equals(returnType.name())) {
                            throw new IllegalArgumentException(
                                    method.name() + " of Repository " + repositoryClassInfo
                                            + " is meant to be a delete query and can therefore only have a void or long return type");
                        }
                        if ((finalSortParameterIndex != null) || finalPageableParameterIndex != null) {
                            throw new IllegalArgumentException(
                                    method.name() + " of Repository " + repositoryClassInfo
                                            + " is meant to be a delete query and therefore doesn't " +
                                            "support Pageable and Sort method parameters");
                        }

                        AnnotationInstance modifyingAnnotation = method.annotation(DotNames.SPRING_DATA_MODIFYING);
                        handleFlushAutomatically(modifyingAnnotation, bc, entityClass);

                        // call JpaOperations.delete()
                        Expr delete = bc.invokeStatic(
                                MethodDesc.of(AdditionalJpaOperations.class, "deleteWithCascade",
                                        long.class, AbstractManagedJpaOperations.class, Class.class, String.class,
                                        Object[].class),
                                ops, entityClass,
                                Const.of(parseResult.getQuery()), paramsArray);

                        handleClearAutomatically(modifyingAnnotation, bc, entityClass);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove the Sort/Pageable parameter from the deleteBy method
  2. If limited deletion is genuinely required, use @Query with JPQL delete and setMaxResults semantics via a custom method, or delete selected entities loaded via findAll(Pageable)
  3. Keep deletion methods simple: deleteByCriteria matching all rows, returning void or long

Example fix

// before
long deleteByStatus(String status, Pageable pageable);

// after
long deleteByStatus(String status);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure deleteBy methods take no Pageable/Sort
for (Method m : PersonRepository.class.getDeclaredMethods()) {
    if (m.getName().startsWith("deleteBy") && Arrays.stream(m.getParameterTypes())
            .anyMatch(t -> Pageable.class.isAssignableFrom(t) || Sort.class.isAssignableFrom(t)))
        throw new IllegalStateException(m.getName() + " must not take Pageable/Sort");
}

Prevention

When it happens

Trigger: Declaring e.g. long deleteByStatus(String status, Pageable pageable) or void deleteByExpired(boolean expired, Sort sort) — a DELETE query type with finalSortParameterIndex != null or finalPageableParameterIndex != null.

Common situations: Mass-adding Pageable parameters during a pagination refactor; wanting to 'delete only the first N matches' and reaching for Pageable; copy-paste from a paginated finder.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/0db7bac4aa336313. Report an issue: GitHub.