Is it possible to have an enum field in a class persisted with OrmLite? Is it possible to have an enum field in a class persisted with OrmLite? sqlite sqlite

Is it possible to have an enum field in a class persisted with OrmLite?


ORMLite can persist enums either as the VARCHAR enum name (default):

// this saves it as a string in the database@DatabaseFieldOurEnum ourEnum;...private enum OurEnum {    FIRST,    SECOND, ;}

As an alternative, you can save the ordinal INTEGER.

// this saves it as an integer in the database@DatabaseField(dataType = DataType.ENUM_INTEGER)OurEnum ourEnum;

Although you can store the ordinal, the VARCHAR name version (which is the default) is recommended since the ordinal value can change if you add or remove entries from the enum.

For both enum types, you can specify an unknownEnumName = "..." field which helps with forward and backward compatibility. If the database contains an unknown value for the enum then the object that is returned by the DAOs will have this enum value.

@DatabaseField(unknownEnumName = "FIRST")OurEnum ourEnum;