I got an entity MyEntity with a field MyField. This field only accepts the following values: S11, S12, S219 and S231.
To realise this, I used an enum:
@Entity
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column
@Enumerated(EnumType.STRING)
private MyEnum myEnum;
// ...
}
public enum MyEnum{
S11("description of 11"), //
S12("description of 12"), //
S219("description of 219"), //
S231("description of 231");
private String description;
private MyEnum(String description) {
this.description = description;
}
}
Now I got a countryLocation which should be conform with ISO 3166-1 alpha-2. Is there any nice way to solve this problem? At the moment I just mapped this like:
@Entity
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column
@Size(min = 2, max = 2)
private String countryLocation;
// ...
}