{"record":{"id":"b261ddbe0dcc6756","repo":"mybatis/mybatis-3","slug":"does-not-represent-an-enum-type","errorCode":null,"errorMessage":"{} does not represent an enum type.","messagePattern":"(.+?) does not represent an enum type\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/type/EnumOrdinalTypeHandler.java","lineNumber":38,"sourceCode":"import java.sql.ResultSet;\nimport java.sql.SQLException;\n\n/**\n * @author Clinton Begin\n */\npublic class EnumOrdinalTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {\n\n  private final Class<E> type;\n  private final E[] enums;\n\n  public EnumOrdinalTypeHandler(Class<E> type) {\n    if (type == null) {\n      throw new IllegalArgumentException(\"Type argument cannot be null\");\n    }\n    this.type = type;\n    this.enums = type.getEnumConstants();\n    if (this.enums == null) {\n      throw new IllegalArgumentException(type.getSimpleName() + \" does not represent an enum type.\");\n    }\n  }\n\n  @Override\n  public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException {\n    ps.setInt(i, parameter.ordinal());\n  }\n\n  @Override\n  public E getNullableResult(ResultSet rs, String columnName) throws SQLException {\n    int ordinal = rs.getInt(columnName);\n    if (ordinal == 0 && rs.wasNull()) {\n      return null;\n    }\n    return toOrdinalEnum(ordinal);\n  }\n\n  @Override","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/type/EnumOrdinalTypeHandler.java#L20-L56","documentation":"EnumOrdinalTypeHandler validates that the Class passed to its constructor is really an enum by calling type.getEnumConstants(); a null return means the class is not an enum type, and the handler aborts with this IllegalArgumentException naming the offending class.","triggerScenarios":"Registering EnumOrdinalTypeHandler (or EnumTypeHandler) for a plain class — a class containing enum-like constants, an interface, or a non-enum POJO specified via javaType= or defaultEnumTypeHandler.","commonSituations":"Setting <setting name=\"defaultEnumTypeHandler\" .../> to EnumOrdinalTypeHandler while the model also contains non-enum classes; mistyping the javaType so it resolves to a wrapper or interface instead of the enum.","solutions":["Register the handler only for actual enum types: verify Class.isEnum() (or @Alias target) before registering","Fix the javaType value in the configuration to point at the real enum class","For constant-holder classes (public static final ints), use a regular type handler, not an enum handler"],"exampleFix":"// before\n<typeHandler handler=\"...EnumOrdinalTypeHandler\" javaType=\"com.example.StatusHolder\"/>\n\n// after\n<typeHandler handler=\"...EnumOrdinalTypeHandler\" javaType=\"com.example.Status\"/> // real enum","handlingStrategy":"validation","validationCode":"if (!SomeClass.class.isEnum()) {\n  throw new IllegalArgumentException(SomeClass.class.getName() + \" is not an enum; cannot use an enum TypeHandler\");\n}","typeGuard":"static boolean isEnumType(Class<?> c) { return c != null && c.isEnum(); }","tryCatchPattern":null,"preventionTips":["Guard registrations: only bind enum handlers to Class.isEnum() types","Use defaultEnumTypeHandler carefully — it applies to enums only, but verify each javaType you register explicitly"],"tags":["mybatis","enum","type-handler","registration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}