I hava a POJO which contains an enum property.
[Speed.java]
public class SpeedEntry implements Serializable {
[...]
private int idSpeed;
private SpeedStatus status; // enum Property
[...]
[SpeedStatus.java]
public enum SpeedStatus {
[...]
VALID(1), INVALID(2), UNKNOWN(0); // Possible values.
private int value;
// Default constructor
private SpeedStatus(final int pValue) {
this.value = pValue;
}
[...]
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 INT(11).
In this case, doing the INSERT was quite direct accessing its internal value property with:
#{status.value}
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 resultMap:
[speedMapper.xml]
<resultMap id="speedMap" type="Speed">
<result property="idSpeed" column="idSpeed" />
<result column="status" property="status.value"
typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>
</resultMap>
So...it is possible to achieve what I am looking for? Is there any simple clarifying example around there?
What is the best alternative? Should I change the type stored in the database to "enum" ?
Thanks in advance.