Blog

The Best Way To Store Enums with JPA and Hibernate

Storing enums in a database can be somewhat tricky. JPA and Hibernate provide 2 standard ways of storing enums: as text or as a number. Each of these ways has its disadvantages. In this post I will describe these disadvantages and then I’m going to reveal a third way, which solves all of them. First Standard Way: Storing as Numbers This is exactly what it sounds like. When storing an enum value in a database column, the column data type is a number (most commonly integer) and it stores the ordinal value of the enum constant. For instance, if we...