Column数据生成策略和主键生成策略

@Entity
@Table(name="tb_user")
public class User {

    /**
     * @GeneratedValue 表示主键生成策略
     *  GenerationType.AUTO  表示自动【默认】  Hibernate会自动检测你配置的数据库产品类型,自动选择适合该数据库产品的主键生成策略
     *  GenerationType.IDENTITY 表示自动递增  mysql sqlServer DB2  SQLITE Sysbase
     *  GenerationType.SEQUENCE 表示序列  DB2 Oracle
     *  GenerationType.TABLE    所有数据库支持这种,性能低
     */
    @Id
    @GeneratedValue
    private Long id; //要求:主键,使用数据库的自动生成策略

    @Column(name="name",length=20,nullable=false,unique=true)
    private String name;  //要求:varchar(20),数据库名称为username,不能为空,唯一

    private String password;

    /**
     * insertable 插入数据的时候是否允许插入这个列的值,默认是true
     * updatable  修改数据的时候是否允许修改这个列的值,默认是true
     */
    @Column(name="age",insertable=false)
    private Integer age = 25; //要求:默认值是25,在插入数据时不允许覆盖(添加数据时不操作该字段)

    private Boolean sex;// 数据库没有布尔类型,bit对象

    @Column(name="salary",columnDefinition="decimal(9,2) check(salary>0.0)")
    private BigDecimal salary;// 9,2 工资不能为负数 check(salary>0.0)

    @Column(name="createTime",updatable=false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;//包含年月日时分秒,不允许修改

    @Temporal(TemporalType.DATE)
    private Date birthday;//包含年月日

    @Temporal(TemporalType.TIME)
    private Date time;//包含时分秒

    @Lob//长字符串
    private String text;//这是一个大文本

    @Transient//临时状态
    private String temp;//这一个字段是临时字段,不需要同步到数据库


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean getSex() {
        return sex;
    }

    public void setSex(Boolean sex) {
        this.sex = sex;
    }

    public BigDecimal getSalary() {
        return salary;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getTemp() {
        return temp;
    }

    public void setTemp(String temp) {
        this.temp = temp;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值