JPA Enum ORDINAL vs STRING

后端 未结 8 1541
予麋鹿
予麋鹿 2021-02-01 13:32

It\'s possible to define enumerations in JPA using either

@Enumerated(EnumType.ORDINAL)

or

@Enumerated(EnumType.STRING)
         


        
8条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 13:53

    I would prefer EnumType.STRING. A disadvantage of EnumType.ORDINAL is the effect of time and the desire to keep enums in a logical order. With EnumType.ORDINAL any new enum elements must be added to the end of the list or you will accidentally change the meaning of all your records. please check this link: https://tomee.apache.org/examples-trunk/jpa-enumerated/

提交回复
热议问题