How to set a default entity property value with Hibernate

后端 未结 17 2320
一整个雨季
一整个雨季 2020-11-28 02:53

How do I set a default value in Hibernate field?

17条回答
  •  一整个雨季
    2020-11-28 02:59

    One solution is to have your getter check to see if whatever value you are working with is null (or whatever its non-initialized state would be) and if it's equal to that, just return your default value:

    public String getStringValue(){
         return (this.stringValue == null) ? "Default" : stringValue;
    }
    

提交回复
热议问题