How should I store an Java Enum in JavaDB?
        Posted  
        
            by Jonas
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jonas
        
        
        
        Published on 2010-05-10T10:39:29Z
        Indexed on 
            2010/05/10
            10:44 UTC
        
        
        Read the original article
        Hit count: 383
        
How should I store an Java Enum in JavaDB?
Should I try to map the enums to SMALLINT and keep the values in source code only? The embedded database is only used by a single application. Or should I just store the values as DECIMAL? None of these solutions feels good/robust for me. Is there any better alternatives?
Here is my enum:
import java.math.BigDecimal;
public enum Vat {
    NORMAL(new BigDecimal("0.25")),
    FOOD(new BigDecimal("0.12")),
    BOOKS(new BigDecimal("0.06")),
    NONE(new BigDecimal("0.00"));
    private final BigDecimal value;
    Vat(BigDecimal val) {
        value = val;
    }
    public BigDecimal getValue() {
        return value;
    }
}
I have read other similar questions on this topic, but the problem or solution doesn't match my problem. Enum storage in Database field, Best method to store Enum in Database, Best way to store enum values in database - String or Int
© Stack Overflow or respective owner