quarkusio/quarkus · error · IllegalArgumentException

Couldn't find id field of ${classInfo}

Error message

Couldn't find id field of ${classInfo}

What it means

EntityClassHelper.getIdField walks the entity's class hierarchy through the Jandex index looking for a field that is the entity id. When no id field is found before reaching the top of the hierarchy, the extension fails the build with this IllegalArgumentException. Spring Data REST needs the id to generate endpoint paths and resource handling.

Source

Thrown at extensions/spring-data-rest/deployment/src/main/java/io/quarkus/spring/data/rest/deployment/EntityClassHelper.java:54

    public FieldInfo getIdField(String className) {
        return getIdField(index.getClassByName(DotName.createSimple(className)));
    }

    public FieldInfo getIdField(ClassInfo classInfo) {
        ClassInfo tmpClassInfo = classInfo;
        while (tmpClassInfo != null) {
            for (FieldInfo field : tmpClassInfo.fields()) {
                if (field.hasAnnotation(DotName.createSimple(Id.class.getName()))) {
                    return field;
                }
            }
            if (tmpClassInfo.superName() != null) {
                tmpClassInfo = index.getClassByName(tmpClassInfo.superName());
            } else {
                tmpClassInfo = null;
            }
        }
        throw new IllegalArgumentException("Couldn't find id field of " + classInfo);
    }

    public MethodDesc getSetter(String className, FieldInfo field) {
        return getSetter(index.getClassByName(DotName.createSimple(className)), field);
    }

    public MethodDesc getSetter(ClassInfo entityClass, FieldInfo field) {
        MethodDesc setter = getMethod(entityClass, JavaBeanUtil.getSetterName(field.name()), field.type());
        if (setter != null) {
            return setter;
        }
        return ClassMethodDesc.of(
                ClassDesc.of(entityClass.toString()),
                EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + field.name(),
                CD_void,
                Jandex2Gizmo.classDescOf(field.type()));
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Add an explicit @Id-annotated field to the entity (or its superclass within the indexed hierarchy)
  2. Use @EmbeddedId on a field for composite keys so the field walk finds it
  3. Verify the superclass holding the id is present in the index (quarkus.index-dependency for its JAR)
  4. Inspect the entity for typos in the annotation import (must be jakarta.persistence.Id)

Example fix

// before
@Entity
public class Item {
    @EmbeddedId private ItemKey key; // key class not embeddable/indexed
}

// after
@Entity
public class Item {
    @EmbeddedId
    private ItemKey key; // @Embeddable ItemKey, in indexed module
}
Defensive patterns

Strategy: validation

Validate before calling

// Unit test guard:
boolean hasId = java.util.Arrays.stream(Item.class.getDeclaredFields())
    .anyMatch(f -> f.isAnnotationPresent(jakarta.persistence.Id.class)
        || f.isAnnotationPresent(jakarta.persistence.EmbeddedId.class));
if (!hasId) throw new IllegalStateException("Entity exposed via REST needs an id field");

Prevention

When it happens

Trigger: A repository projected into a Spring Data REST resource whose entity lacks a field annotated with @Id/@EmbeddedId (including inherited fields); the id is exposed only via a method the field-walk doesn't recognize, or the id comes from an unindexed superclass chain that resolves to null.

Common situations: Entities using @IdClass without an actual @Id field; id defined via getter-only mapping the helper doesn't scan; id in a superclass from a library where index traversal stops (superName null or class missing).

Related errors


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