quarkusio/quarkus · error · IllegalArgumentException

Method ${method} of Repository ${repository}has invalid para

Error message

Method ${method} of Repository ${repository}has invalid parameters - only a single dynamic projection parameter of type Class can be specified

What it means

Dynamic projections are supported via a single parameter of type Class<T> at the end of a derived method. If a method declares two or more such Class parameters, DerivedMethodsAdder.add throws this error at build time because only one dynamic projection target can be bound to the generated query.

Source

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

                parameterTypesStr[i] = parameterType.toString();
                if (DotNames.SPRING_DATA_PAGEABLE.equals(parameterType)
                        || DotNames.SPRING_DATA_PAGE_REQUEST.equals(parameterType)) {
                    if (pageableParameterIndex != null) {
                        throw new IllegalArgumentException("Method " + method.name() + " of Repository " + repositoryClassInfo
                                + "has invalid parameters - only a single parameter of type" + DotNames.SPRING_DATA_PAGEABLE
                                + " can be specified");
                    }
                    pageableParameterIndex = i;
                } else if (DotNames.SPRING_DATA_SORT.equals(parameterType)) {
                    if (sortParameterIndex != null) {
                        throw new IllegalArgumentException("Method " + method.name() + " of Repository " + repositoryClassInfo
                                + "has invalid parameters - only a single parameter of type" + DotNames.SPRING_DATA_SORT
                                + " can be specified");
                    }
                    sortParameterIndex = i;
                } else if (isDynamicProjectionParameter(paramType, method)) {
                    if (dynamicProjectionParameterIndex != null) {
                        throw new IllegalArgumentException("Method " + method.name() + " of Repository " + repositoryClassInfo
                                + "has invalid parameters - only a single dynamic projection parameter of type "
                                + DotNames.CLASS + " can be specified");
                    }
                    dynamicProjectionParameterIndex = i;
                } else {
                    queryParameterIndexes.add(i);
                }
            }

            MethodNameParser.Result parseResult = methodNameParser.parse(method);
            if (parseResult.getParamCount() != queryParameterIndexes.size()) {
                throw new IllegalArgumentException("The number of parameters of method " + method.name() + " of Repository "
                        + repositoryClassInfo
                        + " does not match the number of parameter needed (inferred from the method name)");
            }

            // Need effectively final copies for use in lambdas
            final Integer finalPageableParameterIndex = pageableParameterIndex;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Keep a single Class<T> parameter and select the projection per call
  2. Remove the redundant Class parameter and define separate derived methods per projection type
  3. Return entities and map to different DTOs in service code
  4. Use fixed return types (entity or one interface projection) instead of dynamic projection if only one shape is ever needed

Example fix

// before
<T, U> List<T> findByName(String n, Class<T> view1, Class<U> view2);

// after
<T> List<T> findByName(String n, Class<T> view);
Defensive patterns

Strategy: validation

Validate before calling

long projCount = Arrays.stream(m.getParameterTypes())
    .filter(t -> t == Class.class).count();

Prevention

When it happens

Trigger: Declaring e.g. <T> List<T> findByName(String n, Class<T> type1, Class<T> type2); the second Class parameter detected by isDynamicProjectionParameter triggers the throw.

Common situations: Trying to project to multiple shapes at once; copy-paste of a projection method then adding another Class param; misunderstanding that each Class param maps to a different view.

Related errors


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