Enum in Hibernate, persisting as an enum

后端 未结 5 1878
梦如初夏
梦如初夏 2020-11-29 05:07

In my MySQL database, there\'s the column \"gender enum(\'male\',\'female\')\"

I\'ve created my enum \"com.mydomain.myapp.enums.Gender\", and in my Person

5条回答
  •  -上瘾入骨i
    2020-11-29 05:37

    Try to use @Enumerated(EnumType.STRING) and define your enum like this

    enum Gender {
      male,
      female
    }
    

    Note lower case values.

    This will work at least with VARCHAR columns. It will store enum as string 'male' or 'female'.

提交回复
热议问题