Enum in Hibernate, persisting as an enum

Posted by niklassaers on Stack Overflow See other posts from Stack Overflow or by niklassaers
Published on 2010-01-29T08:24:31Z Indexed on 2010/04/26 0:53 UTC
Read the original article Hit count: 172

Filed under:

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 entity I'm defined "Gender gender".

Now I'd want to keep the enum type in my MySQL database, but when I launch my application I get:

Wrong column type in MyApp.Person for column Gender. Found: enum, expected: integer

Why is this? This would be the equivalent as if I'd annotated my "Gender gender" with "@Enumerated(EnumType.ORDINAL)", which I haven't. EnumType seems only to be able to be either ORDINAL or STRING, so how do I specify that it should treat the field as an enum, not as an int? (not that there's much difference, but enough for it to get upset about it.)

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate