Most projects have some kind of data that is essentially static between versions and well suited for use as an enumeration, such as statuses, transaction types, error codes, etc. For example, for the sake of, I just use a common list of states
public enum Status { ACTIVE(10, "Active"); EXPIRED(11, "Expired"); }
I would like to know what others are doing in terms of storing data like this. I see several options, each of which has some obvious advantages and disadvantages:
- Save possible statuses in the status table and save all possible status domain objects cached for use throughout the application.
- Use only the listing and don’t keep the list of available statuses, creating a consistency of holy war data between me and my database administrator
- Keep statuses and maintain enumeration in code, but do not bind them together, creating duplicate data.
My advantage is the second option, although my database administrator claims that our end users may need access to raw data to create reports, and not to save statuses will lead to an incomplete data model (counter argument: this can be solved with the documentation).
Is there an agreement that most people use here? What are the experiences of people with each and are there other alternatives?
Edit:
After thinking about this for a while, my real hard struggle is with handling id values ​​associated with statuses in the database. These values ​​will be inserted as default data during application installation. At this point, they will have identifiers that can be used as foreign keys in other tables. I feel that my code should know about these identifiers so that I can easily get status objects and assign them to other objects. What should I do with this? I could add another field, such as “code”, to look at things, or just look at the statuses by name, which is not good.
java enums design types persistence
Rob Hruska Jan 29 '09 at 15:37 2009-01-29 15:37
source share