How to set default boolean value in JPA

前端 未结 9 1517
遥遥无期
遥遥无期 2021-02-01 13:53

I have an attribute

private boolean include;

I would like to set its default value to true, so that in the database it must display True from d

9条回答
  •  醉话见心
    2021-02-01 14:23

    The easy way to set a default column value is to set it directly as an entity property value:

    @Entity
    public class Student {
        @Id
        private Long id;
        private String name = "Ousama";
        private Integer age = 30;
        private Boolean happy = false;
    }
    

提交回复
热议问题