Dev Tools · 2h ago
JPA Enum Default Can Silently Corrupt Database Records
JPA's default @Enumerated(ORDINAL) stores enum positions as integers, making data vulnerable to corruption when enum order changes. Inserting a new value like CANCELLED shifts subsequent ordinals, causing existing records to map to wrong statuses without errors. Developers should use explicit ordinal tests or switch to STRING storage to prevent silent data corruption.
Meridian48 take
This is a classic footgun that every Java developer using JPA should know, but the article's alarmist framing overstates the risk—most teams avoid ordinals in practice.
jpaenum-corruption