quarkusio/quarkus · error · IllegalArgumentException

Couldn't find id field of ${classInfo}

Error message

Couldn't find id field of ${classInfo}

What it means

During REST Data Panache build-time indexing, the extension walks the entity class hierarchy (via Jandex) looking for the ID field. If the walk exhausts the hierarchy without finding a field named 'id', it throws IllegalArgumentException. This means the resource's entity type has no recognizable identifier.

Source

Thrown at extensions/panache/hibernate-orm-rest-data-panache/deployment/src/main/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/EntityClassHelper.java:43

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

    private FieldInfo getIdField(ClassInfo classInfo) {
        ClassInfo tmpClassInfo = classInfo;
        while (tmpClassInfo != null) {
            for (FieldInfo field : tmpClassInfo.fields()) {
                if (field.hasAnnotation(JAVAX_PERSISTENCE_ID)) {
                    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 MethodDescriptor getSetter(String className, FieldInfo field) {
        return getSetter(index.getClassByName(DotName.createSimple(className)), field);
    }

    private MethodDescriptor getSetter(ClassInfo entityClass, FieldInfo field) {
        MethodDescriptor setter = getMethod(entityClass, JavaBeanUtil.getSetterName(field.name()), field.type());
        if (setter != null) {
            return setter;
        }
        return MethodDescriptor.ofMethod(entityClass.toString(),
                EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + field.name(), void.class, field.type().name().toString());
    }

    private MethodDescriptor getMethod(ClassInfo entityClass, String name, Type... parameters) {
        if (entityClass == null) {
            return null;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Add an @Id field named 'id' to the entity class
  2. If the key must have another name, check you are using the correct resource interface matching the entity
  3. Rebuild so Jandex indexes the entity module (add Jandex index via jandex-maven-plugin for dependency jars)
  4. Verify the entity is on the application's indexed classpath (not in an unindexed external jar)

Example fix

// before
class Customer extends SomeBaseEntity {
    @Id
    private Long customerNumber;
}
// after
class Customer extends SomeBaseEntity {
    @Id
    private Long id; // rename or add an 'id' field
}
Defensive patterns

Strategy: validation

Validate before calling

if (!java.lang.reflect.Modifier.isAbstract(entityClass.getSuperclass().getName()) ) {
    boolean hasId = java.util.Arrays.stream(entityClass.getDeclaredFields())
        .anyMatch(f -> f.isAnnotationPresent(jakarta.persistence.Id.class)
                   || f.isAnnotationPresent(jakarta.persistence.EmbeddedId.class));
    if (!hasId) throw new IllegalStateException(entityClass + " has no @Id field");
}

Type guard

static boolean hasPanacheId(Class<?> c) {
    for (Class<?> k = c; k != null && k != Object.class; k = k.getSuperclass()) {
        for (Field f : k.getDeclaredFields())
            if (f.isAnnotationPresent(jakarta.persistence.Id.class)) return true;
    }
    return false;
}

Prevention

When it happens

Trigger: Registering a Panache REST Data resource interface (e.g. implementing PanacheEntityResource or a custom repository interface) whose bound entity class has no 'id' field and whose superclasses contain none either.

Common situations: Entity with a custom primary key field name (e.g. @Id Long userId) that Panache REST Data cannot detect; entity not annotated with @Id at all; stale/incomplete Jandex index of an external entity class.

Related errors


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