title: MyBatis retrieve Integer as Enum from MySql DB
body: <p>I hava a POJO which contains an enum property.</p>
  
  <p><strong>[Speed.java]</strong></p>
  
  <pre><code>public class SpeedEntry implements Serializable {
  
      [...]
  
      private int idSpeed;
      private SpeedStatus status; // enum Property
  
      [...]
  </code></pre>
  
  <p><strong>[SpeedStatus.java]</strong></p>
  
  <pre><code>public enum SpeedStatus {
  
  [...]
  
  VALID(1), INVALID(2), UNKNOWN(0);   // Possible values.
  
  private int value;
  
  // Default constructor
  private SpeedStatus(final int pValue) {
      this.value = pValue;
  }
  [...]
  </code></pre>
  
  <p>And I would like to store and retrieve the Speed object and get its properties filled as usual with MyBatis. 
  The column assigned to SpeedStatus was created as an <strong>INT(11)</strong>.</p>
  
  <p>In this case, doing the <strong>INSERT</strong> was quite direct accessing its internal value property with:</p>
  
  <pre><code>#{status.value}
  </code></pre>
  
  <p>However, retrieving the object and getting its enum value filled from the integer stored in the database has not been as easier as inserting it. I tried, without luck, using a <strong>resultMap</strong>:</p>
  
  <p><strong>[speedMapper.xml]</strong></p>
  
  <pre><code>&lt;resultMap id="speedMap" type="Speed"&gt;
          &lt;result property="idSpeed" column="idSpeed" /&gt;
          &lt;result column="status" property="status.value" 
              typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/&gt;
  &lt;/resultMap&gt;
  </code></pre>
  
  <p>So...<strong>it is possible to achieve what I am looking for?</strong> 
  Is there any simple clarifying example around there?</p>
  
  <p>What is the best alternative? Should I change the type stored in the database to "enum" ?</p>
  
  <p>Thanks in advance.</p>