java - 插入数据库时如何修复主键的重复条目?
问题描述
我有一个 android 应用程序,用户在表中插入记录。该应用程序已经运行了几个月。在过去的几天里,我收到了主要错误的重复条目。我不确定问题是什么。
我正在为我的实体使用 GenerationType 序列。会不会是序列号关闭了?如果是这样,为什么会这样?我还从另一个应用程序添加到此表中,这可能是问题吗?
我试过改变记录插入的方式,但我仍然得到同样的错误。也许如果我知道为什么会突然发生这种情况,我就能找出代码。
@Entity(name="bmwsales")
@Table(name="bmwsales")
public class Bmwsales implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private Integer id;
@Column(name="customerfirstname")
private String customerfirstname;
..................
服务实施地点:
@Override
public void addBmwvehicle(Bmwsales vehicle) {
rolllogger.info("add bmw customer vehicle");
bmwsalesRepository.save(vehicle);
}
错误:
Duplicate entry '35475' for key 'PRIMARY'
org.hibernate.engine.jdbc.spi.SqlExceptionHelper in logExceptions at line 131
org.hibernate.engine.jdbc.spi.SqlExceptionHelper in convert at line 110
org.hibernate.engine.jdbc.batch.internal.BatchingBatch in performExecution at line 128
org.hibernate.engine.jdbc.batch.internal.BatchingBatch in doExecuteBatch at line 104
org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl in execute at line 147
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl in executeBatch at line 212
org.hibernate.engine.spi.ActionQueue in executeActions at line 629
org.hibernate.engine.spi.ActionQueue in executeActions at line 474
我希望根据需要插入记录。提前致谢!
解决方案
推荐阅读
- java - 集合的 instanceof 的非法泛型类型
- sql - SQL Server:从 STRING 中识别/提取多个值(例如 ID)以创建逗号分隔的列表
- visual-studio-code - 终端不会在 Visual Studio Code 中打开
- java - Java 客户端服务器程序无限地接受输入
- r - R:如何在不中断循环的情况下获取 last.dump
- laravel - 将存储链接到公共后从数据库中获取图像失败
- node.js - 如何将图像播种到 mongoDB 并使用它们
- python - 我无法用 fastai 创建 ResNet18 的主体
- apache-zookeeper - 如何构建zookeeper抖动导致多次快速选举的场景
- windows - Visual Studio 内核驱动程序部署找不到 WDTF.Interop