Note that using strings will solve the problem of inserting additional values in the middle of the
enumerated type, but it will leave the data vulnerable to changes in the names of the values. For
instance, if we wanted to change PART_TIME_EMPLOYEEto PT_EMPLOYEE, then we would be in trouble. This
is a less likely problem, though, because changing the names of an enumerated type would cause all
the code that uses the enumerated type to have to change also. This would be a bigger bother than
reassigning values in a database column.
In general, storing the ordinal will be the best and most efficient way to store enumerated types
as long as the likelihood of additional values inserted in the middle is not high. New values could still
be added on the end of the type without any negative consequences.
One final note about enumerated types is that they are defined quite flexibly in Java. In fact, it is
even possible to have values that contain state. There is currently no support within the JPA for
mapping state contained within enumerated values. Neither is there support for the compromise
đang được dịch, vui lòng đợi..
