quarkusio/quarkus · error · IllegalArgumentException
Couldn't find id field of
Error message
Couldn't find id field of
What it means
During REST Data Panache build-time generation, EntityClassHelper.getIdField walks the entity's class hierarchy via Jandex looking for an @Id field. If none is found up the chain, it throws IllegalArgumentException naming the entity class.
Source
Thrown at extensions/panache/mongodb-rest-data-panache/deployment/src/main/java/io/quarkus/mongodb/rest/data/panache/deployment/EntityClassHelper.java:44
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.type().name().equals(OBJECT_ID) || field.hasAnnotation(BSON_ID_ANNOTATION)) {
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) {
if (entityClass == null) {
return null;
}
MethodInfo methodInfo = entityClass.method(JavaBeanUtil.getSetterName(field.name()), field.type());
if (methodInfo != null) {
return MethodDescriptor.of(methodInfo);
} else if (entityClass.superName() != null) {
return getSetter(index.getClassByName(entityClass.superName()), field);
}
return null;
}View on GitHub (pinned to e1c734241f)
Solutions
- Add an @Id annotated field (e.g. public ObjectId id;) to the entity class or one of its superclasses.
- Verify the superclass holding the id is part of the application and indexed (not an unindexed external jar without Jandex).
- Ensure you use a supported id annotation from the Panache stack (@Id / ObjectId).
Example fix
// before
public class Book {
public String isbn; // no @Id
}
// after
public class Book {
@Id
public ObjectId id;
public String isbn;
} Defensive patterns
Strategy: validation
Validate before calling
// application-side check at startup
if (Book.class.getDeclaredFields().stream().noneMatch(f -> f.isAnnotationPresent(Id.class))) {
throw new IllegalStateException("Book has no @Id field");
} Prevention
- Always give REST-data-panache entities an @Id field (e.g. ObjectId id).
- Keep the @Id in a superclass only if that class is part of the application and indexed.
- Check generated resources early with a build-time test.
When it happens
Trigger: Using mongodb-rest-data-panache with an entity/repository whose entity class has no field annotated @Id (or whose @Id is on an unsupported ancestor not in the index).
Common situations: Migrating entities from another persistence framework that names ids differently (e.g. 'key' without @Id); manually written entities that forgot @Id; ObjectId id fields defined in a parent class excluded from the Jandex index.
Related errors
- Couldn't find id field of ${classInfo}
- Update types are only supported in MongoDB contexts
- Could not find indexed method: . with descriptor and arg ty
- Failed to process ${path}
- Annotation instance ${annotationInstance} does not match ann
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/d292f0ff7e7950e7.
Report an issue: GitHub.