1

I will use the reference tables for the first time so I have some questions about it.

Example Table

------------------------
id | description       |
------------------------
1  | Some description1 |
2  | Some description2 |
3  | Some description3 |
------------------------

1) In order to increase code legibility I want to create enums like example below. Is this best practice to doing this? What do you think?

    public enum JobType {
        SOME_DESC1((short) 1), SOME_DESC2((short) 2), SOME_DESC3((short) 3);

        private Short value;

        JobType(Short value) {
            this.value = value;
        }

        public Short getValue() {
            return value;
        }
    }

2) If I wanted reference tables to be multilingual, how should I do that? Should I create tables like example below? Do you have any other suggestions?

job_type -  job_translation        -   language
   id          job_id    (pk-fk)       lang_code
              lang_code  (pk-fk)       
             description  
1
  • You haven't stated what programming language and libraries you are using to support internationalization. You need to know how many languages you intend to support, and who will be providing the translation services. Those answers will affect any solutions that might be proposed. – BobDalgleish Nov 23 '18 at 19:25
0

1. enums for reference tables

It depends on what you do with your reference table.

If the reference table is part of your data model, but your code doesn't really need to know what's behind, then don't use such enums. The advantage is that you'd keep flexibility ro add new references without changing the code. Typical example:

  • postal code
  • country prefix
  • category of customers

If your code needs to know the reference because of some specific rules, behaviors, etc. Then such enum could help making the code more readable. Be careful however, because you create a hard coupling between code and data (so maybe call it sys_id instead of id to draw attention on this risk).

2. Multilingual references

Yes, exactly. The usual way is to store the reference text with a language code and an id.

This makes it easy to support as many languages as you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.