As the title says there is no way to choose (check constraint) for enum type if you use it in Entity. Conisder this scenario. You want to use Enum that holds value in lowercase in DB you use this enum:
public enum StateEnum {
OK("ok"),
ERROR("error");
private final String value;
private InvoicesInternalStateEnum(String value) {
this.value = value;
}
public String getValue() {
return this.value;
}
}
If you want to store a lowercase varchar in DB you can't do it. If you will make DB form Entity spring will add check constraint from uppercase. There is no way to tell make it from enum value.
It will work if you make enum from lower letter but this is a bad practise and give a SONAR critical code smell. Enum should start from
^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$:
Comment From: quaff
It's related to JPA not Spring. You can use JPA AttributeConverter, but I think adding an exception at SONAR side is the right way.
Comment From: philwebb
As @quaff mentions, this is a JPA issue and nothing to do with Spring Boot.