I have the following MyBatis 3 select statement that selects an ID from the database and should return the enum belonging to that ID:
public enum MyEnum implements ValueEnum<Integer>
{
 RED(1), BLACK(2), BLUE(3);
 private Integer id;
 public Integer getValue()
 {
  return id;
 }
 private MyEnum (Integer id)
 {
 }
}
public abstract class MyEnumTypeHandlerBase<E extends Enum<E> & ValueEnum<T>, T> extends BaseTypeHandler<E>
 private Map<Object, ValueEnum<T>> map = new HashMap<Object, ValueEnum<T>>();
 private JdbcType mappedJdbcType ;
 public MyEnumTypeHandlerBase()
  MappedTypes mappedTypes = this.getClass().getAnnotation(MappedTypes.class);
  MappedJdbcTypes mappedJdbcTypes = this.getClass().getAnnotation(MappedJdbcTypes.class);
  if(mappedJdbcTypes.value().length > 0)
   mappedJdbcType = mappedJdbcTypes.value()[0];
  for(Class<?> clazz : mappedTypes.value())
   ValueEnum<T>[] enumConstants = (ValueEnum[]) clazz.getEnumConstants();
   for(ValueEnum<T> enumConstant : enumConstants)
    T value = enumConstant.getValue();Â
    String key = value.toString();
    map.put(key, enumConstant);
 /******************* Java to JDBC ************************/
 public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException
  if (jdbcType == null && mappedJdbcType == null)
   ps.setString(i, parameter.getValue().toString());
   if(mappedJdbcType != null)
    ps.setObject(i, parameter.getValue(), mappedJdbcType.TYPE_CODE);
   else ps.setObject(i, parameter.getValue(), jdbcType.TYPE_CODE);Â
 /******************* JDBC to Java ************************/
 public E getNullableResult(ResultSet rs, String columnName) throws SQLException
  Object s = rs.getObject(columnName);
  E value = s == null ? null : (E) map.get(s.toString());
 public E getNullableResult(ResultSet rs, int columnIndex) throws SQLException
  Object s = rs.getObject(columnIndex);
  return s == null ? null : (E) map.get(s.toString());
 public E getNullableResult(CallableStatement cs, int columnIndex) throws SQLException
  Object s = cs.getObject(columnIndex);
  return s == null ? null : (E) map.get(s.toString());
This used to work in MyBatis 2.3.5 but since my migration to MyBatis 3 not anymore.