Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 774133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:04:50+00:00 2026-05-14T19:04:50+00:00

How should I store an Java Enum in JavaDB? Should I try to map

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:04:51+00:00Added an answer on May 14, 2026 at 7:04 pm

    My preference is to do as follows:

    • Create a dedicated enum table in your database with columns: YourEnumId smallint, YourEnumName varchar(32).
    • Within your business object table add foreign key references to the enum table.
    • Implement your Java DAO to map enum values to database-specific smallint values when persisting data OR implement stored procedures that accept the enum name (i.e. varchar) and translate it into a smallint when writing the data.

    Advantages

    • Increased normalisation (and hence lower storage overhead) compared with storing the string value explcitly in your database table.
    • Your database data will not be
      corrupted
      if your java enum
      definition changes (e.g. if you
      change the ordering of the values).
    • Your DAO class can fail-fast during
      initialisation by checking that the
      Java enum definition matches the
      contents of the YourEnum table.
    • You can provide views onto the database that return the String enum values (e.g. If you or a user wishes to query the table directly).

    This is similar to cletus’s solution except that the enum encoding is stored explicitly in the database rather than being defined as part of the enum definition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's slightly less complicated than Saint Gerbil proposed: Model.Order order… May 15, 2026 at 11:44 am
  • Editorial Team
    Editorial Team added an answer If you're on windows then that seems about right. Rails… May 15, 2026 at 11:44 am
  • Editorial Team
    Editorial Team added an answer You don't need a specific third table. Django's ManyToManyField -… May 15, 2026 at 11:44 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.