@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;
}
}
Column数据生成策略和主键生成策略
最新推荐文章于 2022-01-25 10:54:26 发布