Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在实体中表示iso规范定义_Hibernate_Jpa_Enums_Iso - Fatal编程技术网

Hibernate 在实体中表示iso规范定义

Hibernate 在实体中表示iso规范定义,hibernate,jpa,enums,iso,Hibernate,Jpa,Enums,Iso,我有一个实体MyEntity和一个字段MyField。此字段仅接受以下值: S11、S12、S219和S231 为了实现这一点,我使用了一个枚举: @Entity public class MyEntity implements Serializable { private static final long serialVersionUID = 1L; @Column @Enumerated(EnumType.STRING) private MyEnum m

我有一个实体MyEntity和一个字段MyField。此字段仅接受以下值: 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;
    }

}
现在我得到了一个符合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;

    // ...

}

你看到这个了吗?使用此解决方案,您将依赖于java版本。。。