How to set a default entity property value with Hibernate

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

How do I set a default value in Hibernate field?

17条回答
  •  时光取名叫无心
    2020-11-28 03:02

    To use default value from any column of table. then you must need to define @DynamicInsert as true or else you just define @DynamicInsert. Because hibernate takes by default as a true. Consider as the given example:

    @AllArgsConstructor
    @Table(name = "core_contact")
    @DynamicInsert
    public class Contact implements Serializable {
    
        @Column(name = "status", columnDefinition = "int default 100")
        private Long status;
    
    }
    

提交回复
热议问题