'Values in Hibernate
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 1:[1]
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Asgar |
