JPA Enum ORDINAL vs STRING

后端 未结 8 1517
予麋鹿
予麋鹿 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 14:03

    Lots of good advice here, but I just wanted to add something I didn't see yet:

    Regardless of the solution you choose, don't forget to add a big fat warning at the top of your enum class saying which should be used. Hopefully other developers will see you've done this and use the same method for saving the enum.

提交回复
热议问题