Enum Properties
Enum fields are stored as integers by default and converted back to enum constants when reading. Enums can also be used as query parameters.
Basic Usage
Enum values work seamlessly as query parameters:
Custom Integer Values with DbValue
By default, enums are stored as their ordinal (position index). If you need stable integer
values that don't change when entries are reordered, implement the DbValue interface:
With DbValue, Priority.HIGH is stored as 30 in the database instead of ordinal 2.
String Storage with enumAsString
To store the enum name as a string instead of an integer, use @DbField(enumAsString = true) or the JPA @Enumerated(EnumType.STRING) annotation:
You can mix ordinal and string fields in the same entity. The storage mode is per-field.
String matching is case-insensitive — a database value of "active", "ACTIVE", or "Active" all resolve to the same enum constant.
Unknown Database Values
When the database contains a value that doesn't match any enum constant:
- Nullable fields (
Status?): receivenull - Non-null fields (
Status): throw an exception