Issue
I want a row in hibernate that only takes ("yes","no"," "), how can I map it?
Something like an ENUM type in SQL but mapped in Hibernate
Solution
You can use ENUM in an Entity class.
Create an enum class like below:
public enum UserSelectionENUM {
YES, NO;
}
and then Map it to your Entity class:
@Column(name = "user_selection")
private UserSelectionENUM userSelection;
By default the Enumurated type is ordinal, which means you'll have to use int
as your datatype in your database.
However if you want to store string in your database you should explicitly define it as
@Column(name = "user_selection")
@Enumerated(EnumType.STRING)
private UserSelectionENUM userSelection;
Answered By - Asgar
Answer Checked By - Mildred Charles (JavaFixing Admin)