【发布时间】:2018-01-13 05:33:09
【问题描述】:
我通过从 .xlsx 文件导入数据在 MySQL 中创建了零件数据库。最后一部分 ID 是 3717。
现在我想将 ID 为 3718 的新记录从我的 web 应用程序插入数据库,其中 ID 是自动生成的,但 @GeneratedValue 注释尝试从“1”生成 ID,然后它抛出 org.springframework.dao.DataIntegrityViolationException 进行复制主键。
如何从数据库中的最后一个零件 ID 开始自动生成 ID?
@Entity
@Table(name = "parts")
public class Part {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private Integer quantity;
private Double price;
public Part() {}
//getters and setters
【问题讨论】:
-
数据库中的id是AutoIncrement吗?
标签: java mysql database spring