0

I'm currently using Hibernate with MySql. I'm trying to map an enum type, which according to several examples seems really straight forward.

However, the column that is generated contains a VARCHAR(255) rather than an enum type like it expected.

Here's the simple enum class.

public enum Gender {
 MALE,
 FEMALE
}

Here's the annotation

@Enumerated(EnumType.STRING)
@Column(name = "gender")
public Gender getGender() {
 return gender;
}

And here's the field that's generated from this

| gender | varchar(255) | NO | | NULL | |

I can't see why the type is a String rather than an enum. I've tried changing the Enum type to Ordinal, but then I just get an Integer rather than a string, still no enum.

Any help would be appreciated.

asked Oct 29, 2014 at 14:59

1 Answer 1

1

I don't think it's possible because ENUM is not a standard SQL datatype. By default @Enumerated is mapped to integer, if EnumType.STRING is used then column is mapped to a string.

answered Oct 29, 2014 at 16:13
Sign up to request clarification or add additional context in comments.

1 Comment

Enum is a supported MySQL datatype - used here in a sample database. This article was recently updated - also links to MySQL documentation. www3.ntu.edu.sg/home/ehchua/programming/sql/… Also - this works stackoverflow.com/questions/1076604/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.