mybatis/mybatis-3 · error · BuilderException

Detected conflicting annotations '%s' and '%s' on '%s'.

Error message

Detected conflicting annotations '%s' and '%s' on '%s'.

What it means

Error "Detected conflicting annotations '%s' and '%s' on '%s'." thrown in mybatis/mybatis-3.

Source

Thrown at src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java:674

  private SqlSource buildSqlSourceFromStrings(String[] strings, Class<?> parameterTypeClass,
      ParamNameResolver paramNameResolver, LanguageDriver languageDriver) {
    return languageDriver.createSqlSource(configuration, String.join(" ", strings).trim(), parameterTypeClass,
        paramNameResolver);
  }

  @SafeVarargs
  private final Optional<AnnotationWrapper> getAnnotationWrapper(Method method, boolean errorIfNoMatch,
      Class<? extends Annotation>... targetTypes) {
    return getAnnotationWrapper(method, errorIfNoMatch, Arrays.asList(targetTypes));
  }

  private Optional<AnnotationWrapper> getAnnotationWrapper(Method method, boolean errorIfNoMatch,
      Collection<Class<? extends Annotation>> targetTypes) {
    String databaseId = configuration.getDatabaseId();
    Map<String, AnnotationWrapper> statementAnnotations = targetTypes.stream()
        .flatMap(x -> Arrays.stream(method.getAnnotationsByType(x))).map(AnnotationWrapper::new)
        .collect(Collectors.toMap(AnnotationWrapper::getDatabaseId, x -> x, (existing, duplicate) -> {
          throw new BuilderException(
              String.format("Detected conflicting annotations '%s' and '%s' on '%s'.", existing.getAnnotation(),
                  duplicate.getAnnotation(), method.getDeclaringClass().getName() + "." + method.getName()));
        }));
    AnnotationWrapper annotationWrapper = null;
    if (databaseId != null) {
      annotationWrapper = statementAnnotations.get(databaseId);
    }
    if (annotationWrapper == null) {
      annotationWrapper = statementAnnotations.get("");
    }
    if (errorIfNoMatch && annotationWrapper == null && !statementAnnotations.isEmpty()) {
      // Annotations exist, but there is no matching one for the specified databaseId
      throw new BuilderException(String.format(
          "Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s].",
          method.getDeclaringClass().getName(), method.getName(), databaseId));
    }
    return Optional.ofNullable(annotationWrapper);
  }

View on GitHub (pinned to 008069adb1)

Solutions

  1. Remove one of the conflicting annotations from the method so only one remains.
  2. If both annotations are needed, refactor the method into two separate mapper methods each carrying one annotation.
  3. Check the MyBatis documentation for the pair of annotations reported; they are mutually exclusive by design.

When it happens

Trigger: Thrown at src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java:674 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14). Data as JSON: /api/errors/9a0ff4e4c5892dae. Report an issue: GitHub.