mybatis/mybatis-3 · error · IllegalArgumentException
{} does not represent an enum type.
Error message
{} does not represent an enum type. What it means
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.
Source
Thrown at src/main/java/org/apache/ibatis/type/EnumOrdinalTypeHandler.java:38
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author Clinton Begin
*/
public class EnumOrdinalTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {
private final Class<E> type;
private final E[] enums;
public EnumOrdinalTypeHandler(Class<E> type) {
if (type == null) {
throw new IllegalArgumentException("Type argument cannot be null");
}
this.type = type;
this.enums = type.getEnumConstants();
if (this.enums == null) {
throw new IllegalArgumentException(type.getSimpleName() + " does not represent an enum type.");
}
}
@Override
public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException {
ps.setInt(i, parameter.ordinal());
}
@Override
public E getNullableResult(ResultSet rs, String columnName) throws SQLException {
int ordinal = rs.getInt(columnName);
if (ordinal == 0 && rs.wasNull()) {
return null;
}
return toOrdinalEnum(ordinal);
}
@OverrideView on GitHub (pinned to 008069adb1)
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
Example fix
// before <typeHandler handler="...EnumOrdinalTypeHandler" javaType="com.example.StatusHolder"/> // after <typeHandler handler="...EnumOrdinalTypeHandler" javaType="com.example.Status"/> // real enum
Defensive patterns
Strategy: validation
Validate before calling
if (!SomeClass.class.isEnum()) {
throw new IllegalArgumentException(SomeClass.class.getName() + " is not an enum; cannot use an enum TypeHandler");
} Type guard
static boolean isEnumType(Class<?> c) { return c != null && c.isEnum(); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Type argument cannot be null
- Type argument cannot be null
- Failed to invoke constructor {}
- '{}' does not implement TypeHandler.
- Type {typeHandlerType} is not a valid TypeHandler because it
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/b261ddbe0dcc6756.
Report an issue: GitHub.