简体   繁体   English

JPA枚举类型作为数据库中的表

[英]JPA Enum type as table in database

So, my question is next. 所以,我的问题是下一个。 How can I map enum type in a database as a table. 如何将数据库中的枚举类型映射为表。 I want to have a table with values of my Enum.I want to have such structure in database: Model 我想要一个具有我的Enum值的表。我想要在数据库中具有这样的结构: 模型

And such structure of classes in code: 此类代码中的类结构如下:

@Entity
public class MainEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @NotNull
    @Column
    private Integer id;

    @Column
    private Enum enum;

    @NotNull
    @Column
    private String any_other_attribute;

}
public enum Enum implements Serializable {
    First, Second, Third
}

See below link for the detail explanation of Enum with JPA http://tomee.apache.org/examples-trunk/jpa-enumerated/README.html 请参阅下面的链接,以获取使用JPA进行枚举的详细说明http://tomee.apache.org/examples-trunk/jpa-enumerated/README.html

You can use Enumerated Annotation. 您可以使用枚举注释。

@Enumerated(EnumType.STRING) private Rating rating; @Enumerated(EnumType.STRING)私人评分等级;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM