JPA枚举类型作为数据库中的表 [英] JPA Enum type as table in database

查看:114
本文介绍了JPA枚举类型作为数据库中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么,我的问题是下一个.如何将数据库中的枚举类型映射为表.我想要一个具有我的Enum值的表.我想要在数据库中具有这样的结构:模型

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

代码中类的此类结构:

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

推荐答案

有关使用JPA的Enum的详细说明,请参见下面的链接 http://tomee.apache.org/examples-trunk/jpa-枚举/README.html

See below link for the detail explanation of Enum with JPA http://tomee.apache.org/examples-trunk/jpa-enumerated/README.html

您可以使用枚举注释.

@Enumerated(EnumType.STRING) 私人评级;

@Enumerated(EnumType.STRING) private Rating rating;

这篇关于JPA枚举类型作为数据库中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆