JPA存储具有空值的Java枚举

JPA存储具有空值的Java枚举,java,spring-boot,jpa,enums,Java,Spring Boot,Jpa,Enums,我用的是SpringBoot和JPA 在我的实体中,我有一个映射为enum的状态字段。我想将特定于e的枚举值映射为NULL 我试过这样的方法: public enum Status { DELETED(null), ACTIVE(1); private final Integer type; Status(Integer type) { this.type = type; }

我用的是SpringBoot和JPA

在我的实体中,我有一个映射为enum的状态字段。我想将特定于e的枚举值映射为NULL

我试过这样的方法:

public enum Status {

        DELETED(null),
        ACTIVE(1);

        private final Integer type;

        Status(Integer type) {
            this.type = type;
        }

        public int getStatusValue() {
            return type;
        }

        public static Status from(int value) {
            return Status.values()[value];
        }
    }
但这种方法并不能正常工作

当我尝试为我的模型设置“已删除”值并尝试在DB上保存时,状态值为0


有没有一种方法可以设置已删除状态并直接在数据库上设置空值?

您需要为此用例使用属性转换器-看看这个问题,它显示了要遵循的步骤-