代表实体中的iso-norm-definitions

时间:2016-01-05 09:42:04

标签: hibernate jpa enums iso

我有一个带有字段MyField的实体MyEntity。该字段仅接受以下值: S11,S12,S219和S231。

为了实现这一点,我使用了一个枚举:

@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;
    }

}

现在我有了一个countryLocation,应该符合ISO 3166-1 alpha-2。有什么好方法可以解决这个问题吗?目前我只是将其映射为:

@Entity
public class MyEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column
    @Size(min = 2, max = 2)
    private String countryLocation;

    // ...

}

0 个答案:

没有答案