我需要为表中的字段设置自动增量。
这是我的实体类:
@Entity
@Table(name = "UserLogin")
public class User implements Serializable {
private int id;
private String username;
private String password;
private String fname;
private String lname;
private String emailId;
private boolean loginperson;
private String manager;
@Id
@GeneratedValue
@Column(name = "empolyeeId")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "username", nullable = false)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "password", nullable = false)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "firstName", nullable = false)
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
@Column(name = "lastName", nullable = false)
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
@Column(name = "emailId", nullable = false)
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public void setManager(String manager) {
this.manager = manager;
}
@Column(name = "loginperson", nullable = false)
public boolean isLoginperson() {
return loginperson;
}
public void setLoginperson(boolean loginperson) {
this.loginperson = loginperson;
}
@Column(name = "manager", nullable = false)
public String getManager() {
return manager;
}
public String getEmailId() {
return emailId;
}
在这里,我无法为 id 字段设置 Generated 值。但它没有为 id 字段创建自动增量。
我试过了
@GeneratedValue(strategy=GenerationType.AUTO)
和
@GeneratedValue(strategy=GenerationType.IDENTITY)
但是该表没有在 mysql 数据库中创建。
我收到以下日志。
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table UserLogin (empolyeeId integer generated by default as identity (start with 1), emailId varchar(255), firstName varchar(255) not null, lastName varchar(255) not null, loginperson bit not null, manager varchar(255) not null, password varchar(255) not null, username varchar(255) not null, primary key (empolyeeId))
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'generated by default as identity (start with 1), emailId varchar(255), firstName' at line 1