mybatis/mybatis-3 · error · BuilderException

Cannot specify different class on 'value' and 'type' attribu

Error message

Cannot specify different class on 'value' and 'type' attribute of @{annotationSimpleName} at the '{mapperMethod}'.

What it means

Error "Cannot specify different class on 'value' and 'type' attribute of @{annotationSimpleName} at the '{mapperMethod}'." thrown in mybatis/mybatis-3.

Source

Thrown at src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java:265

      targetObject = providerType.getDeclaredConstructor().newInstance();
    }
    CharSequence sql = (CharSequence) providerMethod.invoke(targetObject, args);
    return sql != null ? sql.toString() : null;
  }

  private Class<?> getProviderType(Configuration configuration, Annotation providerAnnotation, Method mapperMethod)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class<?> type = (Class<?>) providerAnnotation.annotationType().getMethod("type").invoke(providerAnnotation);
    Class<?> value = (Class<?>) providerAnnotation.annotationType().getMethod("value").invoke(providerAnnotation);
    if (value == void.class && type == void.class) {
      if (configuration.getDefaultSqlProviderType() != null) {
        return configuration.getDefaultSqlProviderType();
      }
      throw new BuilderException("Please specify either 'value' or 'type' attribute of @"
          + providerAnnotation.annotationType().getSimpleName() + " at the '" + mapperMethod.toString() + "'.");
    }
    if (value != void.class && type != void.class && value != type) {
      throw new BuilderException("Cannot specify different class on 'value' and 'type' attribute of @"
          + providerAnnotation.annotationType().getSimpleName() + " at the '" + mapperMethod.toString() + "'.");
    }
    return value == void.class ? type : value;
  }

}

View on GitHub (pinned to 008069adb1)

Solutions

  1. Use only one of value or type on the provider annotation, or make both reference the same provider class.
  2. Remove the duplicate attribute so a single provider class is specified.

When it happens

Trigger: Thrown at src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java:265 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/9811a8781c5893bd. Report an issue: GitHub.