Enum in Hibernate, persisting as an enum

后端 未结 5 1879
梦如初夏
梦如初夏 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条回答
  •  时光取名叫无心
    2020-11-29 05:52

    My understanding is that MySQL enum type is very proprietary and not well supported by Hibernate, see this comment from Gavin King (this related issue is a bit different but that's not the important part).

    So, I actually think that you'll have to use your own UsereType and I'd recommend to use the Flexible solution - working version from the Java 5 EnumUserType (see Appfuse's Java 5 Enums Persistence with Hibernate for an example).

    Personally, I'd just forget the idea to use MySQL enum, I'm not convinced that the "benefits" are worth it (see this answer for more details).

提交回复
热议问题