最近在搭建Springboot项目时总是出现如下报错:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [hibernate_sequence]
完整报错:
报错
找了很久错误原因,就是没发现。对比以前的项目发现也没啥不同,顿时懵了比...
最后根据hibernate_sequence关键字终于查到了原因。
在使用@GeneratedValue注解时,需要添加策略配置,即@GeneratedValue(strategy = GenerationType.IDENTITY),这样就不会出现问题了。
需要使用hibernate主键生成策略
model示例代码:
package cn.sprivacy.station.model;
import javax.persistence.*;
@Entity
@Table(name = "users")
public class Users {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "emp_code")
private String empCode;
@Column(name = "emp_name")
private String empName;
@Column(name = "job")
private String job;
@Column(name = "is_sys")
private String isSys;
@Column(name = "alias")
private String alias;
@Column(name = "phone")
private String phone;
@Column(name = "identity_card")
private String identityCard;
@Column(name = "org_code")
private String orgCode;
@Column(name = "create_time")
private String createTime;
@Column(name = "modify_time")
private String modifyTime;
@Column(name = "modify_user_id")
private String modifyUserId;
@Column(name = "status")
private String status;
@Column(name = "remark")
private String remark;
@Column(name = "delete_flag")
private Integer deleteFlag;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmpCode() {
return empCode;
}
public void setEmpCode(String empCode) {
this.empCode = empCode == null ? null : empCode.trim();
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName == null ? null : empName.trim();
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job == null ? null : job.trim();
}
public String getIsSys() {
return isSys;
}
public void setIsSys(String isSys) {
this.isSys = isSys == null ? null : isSys.trim();
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias == null ? null : alias.trim();
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone == null ? null : phone.trim();
}
public String getIdentityCard() {
return identityCard;
}
public void setIdentityCard(String identityCard) {
this.identityCard = identityCard == null ? null : identityCard.trim();
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode == null ? null : orgCode.trim();
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime == null ? null : createTime.trim();
}
public String getModifyTime() {
return modifyTime;
}
public void setModifyTime(String modifyTime) {
this.modifyTime = modifyTime == null ? null : modifyTime.trim();
}
public String getModifyUserId() {
return modifyUserId;
}
public void setModifyUserId(String modifyUserId) {
this.modifyUserId = modifyUserId == null ? null : modifyUserId.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
}
网友评论