{"record":{"id":"d292f0ff7e7950e7","repo":"quarkusio/quarkus","slug":"couldn-t-find-id-field-of-d292f0","errorCode":null,"errorMessage":"Couldn't find id field of ","messagePattern":"Couldn't find id field of ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/panache/mongodb-rest-data-panache/deployment/src/main/java/io/quarkus/mongodb/rest/data/panache/deployment/EntityClassHelper.java","lineNumber":44,"sourceCode":"    public FieldInfo getIdField(String className) {\n        return getIdField(index.getClassByName(DotName.createSimple(className)));\n    }\n\n    private FieldInfo getIdField(ClassInfo classInfo) {\n        ClassInfo tmpClassInfo = classInfo;\n        while (tmpClassInfo != null) {\n            for (FieldInfo field : tmpClassInfo.fields()) {\n                if (field.type().name().equals(OBJECT_ID) || field.hasAnnotation(BSON_ID_ANNOTATION)) {\n                    return field;\n                }\n            }\n            if (tmpClassInfo.superName() != null) {\n                tmpClassInfo = index.getClassByName(tmpClassInfo.superName());\n            } else {\n                tmpClassInfo = null;\n            }\n        }\n        throw new IllegalArgumentException(\"Couldn't find id field of \" + classInfo);\n    }\n\n    public MethodDescriptor getSetter(String className, FieldInfo field) {\n        return getSetter(index.getClassByName(DotName.createSimple(className)), field);\n    }\n\n    private MethodDescriptor getSetter(ClassInfo entityClass, FieldInfo field) {\n        if (entityClass == null) {\n            return null;\n        }\n        MethodInfo methodInfo = entityClass.method(JavaBeanUtil.getSetterName(field.name()), field.type());\n        if (methodInfo != null) {\n            return MethodDescriptor.of(methodInfo);\n        } else if (entityClass.superName() != null) {\n            return getSetter(index.getClassByName(entityClass.superName()), field);\n        }\n        return null;\n    }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/mongodb-rest-data-panache/deployment/src/main/java/io/quarkus/mongodb/rest/data/panache/deployment/EntityClassHelper.java#L26-L62","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":"// before\npublic class Book {\n    public String isbn; // no @Id\n}\n// after\npublic class Book {\n    @Id\n    public ObjectId id;\n    public String isbn;\n}","handlingStrategy":"validation","validationCode":"// application-side check at startup\nif (Book.class.getDeclaredFields().stream().noneMatch(f -> f.isAnnotationPresent(Id.class))) {\n    throw new IllegalStateException(\"Book has no @Id field\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["mongodb","panache","build-time","jandex","missing-id"],"backgroundTag":"missing-entity-id-field","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}