quarkusio/quarkus · error · IllegalArgumentException

Annotation ${dotName} was not expected on a target of kind $

Error message

Annotation ${dotName} was not expected on a target of kind ${kind}

What it means

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.

Source

Thrown at extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java:456

            addClassHierarchyToReflectiveList(collector, targetDotName);
            collector.modelTypes.add(targetDotName.toString());
        }
    }

    private void enlistPotentialCdiBeanClasses(Collector collector, DotName dotName) {
        Collection<AnnotationInstance> jpaAnnotations = index.getAnnotations(dotName);

        if (jpaAnnotations == null) {
            return;
        }

        for (AnnotationInstance annotation : jpaAnnotations) {
            AnnotationTarget target = annotation.target();
            ClassInfo beanType = switch (target.kind()) {
                case CLASS -> target.asClass();
                case FIELD -> target.asField().declaringClass();
                case METHOD -> target.asMethod().declaringClass();
                default -> throw new IllegalArgumentException(
                        "Annotation " + dotName + " was not expected on a target of kind " + target.kind());
            };
            DotName beanTypeDotName = beanType.name();
            collector.potentialCdiBeanTypes.add(beanTypeDotName);
        }
    }

    private void enlistPotentialClassReferences(Collector collector, DotName dotName, String... referenceAttributes) {
        Collection<AnnotationInstance> jpaAnnotations = index.getAnnotations(dotName);

        if (jpaAnnotations == null) {
            return;
        }

        for (AnnotationInstance annotation : jpaAnnotations) {
            for (String referenceAttribute : referenceAttributes) {
                var referenceValue = annotation.value(referenceAttribute);
                if (referenceValue == null) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Move the JPA annotation to a supported target: the class, a field, or a getter method
  2. Check for meta-annotation/composition setups that copy the annotation onto constructors or parameters
  3. Inspect which annotation (dotName in the message) and where it is applied; remove it from the unsupported location

Example fix

// before
public class A {
  @Column(name="x") // on a constructor parameter (unsupported)
  public A(@Column(name="x") String x) { ... }
}
// after
public class A {
  @Column(name="x")
  String x;
  public A(String x) { this.x = x; }
}
Defensive patterns

Strategy: validation

Validate before calling

// Ensure JPA annotations only appear on classes/fields/methods in your codebase
for (Annotation ann : field.getAnnotations()) {
    // annotate fields or getters, never constructors/parameters
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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