{"record":{"id":"973311b694871e98","repo":"quarkusio/quarkus","slug":"annotation-dotname-was-not-expected-on-a-target","errorCode":null,"errorMessage":"Annotation ${dotName} was not expected on a target of kind ${kind}","messagePattern":"Annotation (.+?) was not expected on a target of kind (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java","lineNumber":456,"sourceCode":"            addClassHierarchyToReflectiveList(collector, targetDotName);\n            collector.modelTypes.add(targetDotName.toString());\n        }\n    }\n\n    private void enlistPotentialCdiBeanClasses(Collector collector, DotName dotName) {\n        Collection<AnnotationInstance> jpaAnnotations = index.getAnnotations(dotName);\n\n        if (jpaAnnotations == null) {\n            return;\n        }\n\n        for (AnnotationInstance annotation : jpaAnnotations) {\n            AnnotationTarget target = annotation.target();\n            ClassInfo beanType = switch (target.kind()) {\n                case CLASS -> target.asClass();\n                case FIELD -> target.asField().declaringClass();\n                case METHOD -> target.asMethod().declaringClass();\n                default -> throw new IllegalArgumentException(\n                        \"Annotation \" + dotName + \" was not expected on a target of kind \" + target.kind());\n            };\n            DotName beanTypeDotName = beanType.name();\n            collector.potentialCdiBeanTypes.add(beanTypeDotName);\n        }\n    }\n\n    private void enlistPotentialClassReferences(Collector collector, DotName dotName, String... referenceAttributes) {\n        Collection<AnnotationInstance> jpaAnnotations = index.getAnnotations(dotName);\n\n        if (jpaAnnotations == null) {\n            return;\n        }\n\n        for (AnnotationInstance annotation : jpaAnnotations) {\n            for (String referenceAttribute : referenceAttributes) {\n                var referenceValue = annotation.value(referenceAttribute);\n                if (referenceValue == null) {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java#L438-L474","documentation":"While collecting potential CDI bean classes from JPA annotations, JpaJandexScavenger maps an annotation target (class, field, or method) to its declaring class. A JPA annotation applied to a target kind other than CLASS, FIELD, or METHOD (e.g. a constructor, parameter, or type annotation) is unsupported here and throws IllegalArgumentException.","triggerScenarios":"One of the scanned JPA annotations (jpaAnnotations for the given dotName) is attached to a target whose kind() is not CLASS, FIELD, or METHOD — e.g. the annotation is somehow placed on a constructor or type-use position.","commonSituations":"Custom meta-annotations or annotation compositions that place JPA annotations in unusual positions; bytecode/annotation processing that retargets annotations; misuse of @AssociationOverride/@AttributeOverride on unexpected elements in generated code.","solutions":["Move the JPA annotation to a supported target: the class, a field, or a getter method","Check for meta-annotation/composition setups that copy the annotation onto constructors or parameters","Inspect which annotation (dotName in the message) and where it is applied; remove it from the unsupported location"],"exampleFix":"// before\npublic class A {\n  @Column(name=\"x\") // on a constructor parameter (unsupported)\n  public A(@Column(name=\"x\") String x) { ... }\n}\n// after\npublic class A {\n  @Column(name=\"x\")\n  String x;\n  public A(String x) { this.x = x; }\n}","handlingStrategy":"validation","validationCode":"// Ensure JPA annotations only appear on classes/fields/methods in your codebase\nfor (Annotation ann : field.getAnnotations()) {\n    // annotate fields or getters, never constructors/parameters\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply JPA annotations only to classes, fields, or getter methods","Avoid meta-annotation stacks that retarget JPA annotations to constructors/parameters","Review annotation processors that copy annotations to new targets"],"tags":["quarkus","hibernate-orm","annotation-target","jandex"],"backgroundTag":"unsupported-annotation-target","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}