Enumerated with default value, but not name

44 Views Asked by At
public class Document {

    @Id
    @Column(name = "id")
    @GeneratedValue
    private Long id;

    @Column(name = "type")
    private Long subjectType;

    @Column(name = "markup")
    @Enumerated(EnumType.STRING)
    private RuleMarkup nonRuleMarkup = RuleMarkup.MANUAL;
}

public enum RuleMarkup {
    MANUAL("manual markup"),
    NO_REQUIRED("markup not required");

    private final String rule;
}

how to save in DB the default value by enum not the name MANUAL but value 'manual markup'?

getRule() doesn't work because it returns String type

1

There are 1 best solutions below

0
Aleksandr Berestov On

I implemented interface AttributeConverter:

public class RuleMarkupConverter implements AttributeConverter<RuleMarkup, String>

and just marked my fieald as @Column.