mybatis/mybatis-3 · error · BuilderException

Could not find a statement annotation that correspond a curr

Error message

Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s].

What it means

Error "Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s]." thrown in mybatis/mybatis-3.

Source

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

      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);
  }

  public static Class<?> getMethodReturnType(String mapperFqn, String localStatementId) {
    if (mapperFqn == null || localStatementId == null) {
      return null;
    }
    try {
      Class<?> mapperClass = Resources.classForName(mapperFqn);
      for (Method method : mapperClass.getMethods()) {
        if (method.getName().equals(localStatementId) && canHaveStatement(method)) {
          return getReturnType(method, mapperClass);
        }
      }
    } catch (ClassNotFoundException e) {

View on GitHub (pinned to 008069adb1)

Solutions

  1. Add a statement annotation (e.g. @Select) without a databaseId so it serves as the default for the method.
  2. Add a statement annotation whose databaseId matches the current database id shown in the message.
  3. Verify the configured databaseId in your MyBatis configuration matches the databaseId used on the annotation.

When it happens

Trigger: Thrown at src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java:687 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/905d9faf293e532e. Report an issue: GitHub.