quarkusio/quarkus · error · UnableToParseMethodException

Field ${orderField} which was configured as the order field

Error message

Field ${orderField} which was configured as the order field does not exist in the entity. Offending method is ${repositoryMethodDescription}.

What it means

The field name given after 'OrderBy' in the derived method name does not match any field of the entity class. The parser validates the lower-camel-cased order field against the entity's fields and throws UnableToParseMethodException if it is absent.

Source

Thrown at extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/MethodNameParser.java:164

        if (containsLogicOperator(afterByPart, ORDER_BY)) {
            int orderByIndex = afterByPart.indexOf(ORDER_BY);
            if (orderByIndex + ORDER_BY.length() == afterByPart.length()) {
                throw new UnableToParseMethodException(
                        "A field must by supplied after 'OrderBy' . Offending method is " + repositoryMethodDescription + ".");
            }
            String afterOrderByPart = afterByPart.substring(orderByIndex + ORDER_BY.length());
            afterByPart = afterByPart.substring(0, orderByIndex);
            boolean ascending = true;
            if (afterOrderByPart.endsWith("Asc")) {
                ascending = true;
                afterOrderByPart = afterOrderByPart.replace("Asc", "");
            } else if (afterOrderByPart.endsWith("Desc")) {
                ascending = false;
                afterOrderByPart = afterOrderByPart.replace("Desc", "");
            }
            String orderField = lowerFirstLetter(afterOrderByPart);
            if (!entityContainsField(orderField)) {
                throw new UnableToParseMethodException(
                        "Field " + orderField
                                + " which was configured as the order field does not exist in the entity. Offending method is "
                                + repositoryMethodDescription + ".");
            }

            if (ascending) {
                sort = Sort.ascending(orderField);
            } else {
                sort = Sort.descending(orderField);
            }
        }

        List<String> parts = Collections.singletonList(afterByPart); // default when no 'And' or 'Or' exists
        boolean containsAnd = containsLogicOperator(afterByPart, "And");
        boolean containsOr = containsLogicOperator(afterByPart, "Or");
        String[] partsArray = parts.toArray(new String[0]);
        //Spring supports mixing clauses 'And' and 'Or' together in method names
        if (containsAnd && containsOr) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Correct the method name so the OrderBy field matches a real Java field of the entity (case-sensitive after the first letter is lowercased)
  2. If sorting by a nested property, express the path with underscores (e.g. OrderByAddress_CityAsc) or use @Query with an explicit ORDER BY
  3. Sort at call time via Sort.by("name") instead of embedding it in the method name

Example fix

// before
List<User> findByLastnameOrderByUsrNameAsc(String lastname);
// after (entity field is userName)
List<User> findByLastnameOrderByUserNameAsc(String lastname);
Defensive patterns

Strategy: validation

Validate before calling

// Verify the field exists on the entity before naming the method:
// for (Field f : MyEntity.class.getDeclaredFields()) System.out.println(f.getName());

Try / catch

try {
    parser.parse(methodName);
} catch (UnableToParseMethodException e) {
    // fix the OrderBy field to match an entity property
    throw new IllegalStateException("Bad sort field: " + e.getMessage());
}

Prevention

When it happens

Trigger: Declaring e.g. findByLastnameOrderByNaemAsc (misspelled 'name'); using the DB column name instead of the Java field name (OrderByuser_name); ordering by a field that belongs to a related entity without navigating it.

Common situations: Renaming an entity field without updating derived query method names; confusing column names with Java property names; typos in long method names.

Related errors


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