重启服务器上的密钥'PRIMARY'重复输入'1'

时间:2015-08-31 15:00:51

标签: java mysql hibernate

我正在创建一个struts2应用程序并使用hibernate在数据库(MySql)中存储数据。现在,每次重新启动Apache tomcat服务器时,分配给我的新对象的主键值为1,这会导致键'PRIMARY'的重复条目为'1'。我尝试使用生成策略TABLE,以便生成的新Id大于上次生成的值,因为存储最后分配的id的表将是持久的。但我仍然得到这个错误。以下是我的班级声明 `

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name="USER_DETAILS")
public class UserDetails {
    @TableGenerator(name = "employee_gen", table = "id_gen", pkColumnName = "gen_name", valueColumnName = "gen_val", allocationSize = 100)
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "employee_gen")

@Column(name ="USER_ID")
private int userId;
private UserType userType;
@Column(name ="FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
@Column(name ="LOCATION")
private Location location;
public void setUserId(int userId) {
    this.userId = userId;
}
public int getUserId() {
    return userId;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getFirstName() {
    return firstName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
public String getLastName() {
    return lastName;
}
public void setLocation(Location location) {
    this.location = location;
}
public Location getLocation() {
    return location;
}
public void setUserType(UserType userType) {
    this.userType = userType;
}
@Enumerated(EnumType.ORDINAL)
public UserType getUserType() {
    return userType;
}
}

`

0 个答案:

没有答案