Search code examples
javasqlspringrestservice

Should I store data in db or should I store it in enum?


Data is very small like list of fruits and won't be changed often, also only one service will be using this data and serving to other services, please mention advantage and disadvantage of your approach.


Solution

  • I think it is better store it in a database's table.

    If you store it in a enum, when you add, change or delete a fruit you have to compile your code again. In case of change, you will have to update all places (tables columns) where this fruit's name is store.

    In the database you could opt to save it as a single column table or a two columns table (id, fruit_name).

    I will opt the second option. Because if you choose the single column option, and you change a fruit name you will have to change it in all the tables where the fruit name is store (like in enum). A disadvantage with the two columns table is that you will have to make joins with the fruit table to get the fruit name (but make this joins is easy and simple).