gpt4 book ai didi

java - Hibernate 键 '7090' 的重复条目 'PRIMARY'

转载 作者:行者123 更新时间:2023-11-29 03:05:44 25 4
gpt4 key购买 nike

当应用程序尝试在数据库中插入记录行时出现以下错误。

SQL Error: 1062, SQLState: 23000
ERROR org.hibernate.util.JDBCExceptionReporter - Duplicate entry '7089' for key 'PRIMARY'
ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
Caused by: java.sql.BatchUpdateException: Duplicate entry '7090' for key 'PRIMARY'
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1269)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:955)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)

定义是

@Id
@Column(name = "CST_CUSTOMER_ID_PK")
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

发生错误的部分是:

savedCustomer = customerDao.save(customer);
mtmrsLogger.debug("saved customer id:" + savedCustomer.getId());
/**
* Updating Customer Trans Table
*/
updateCustomerTransForMakerChecker(customer, customerform.getAuditDetails());

/**
* Updating Customer Audit
*/
updateCustomerAuditForMakerChecker(customer, customerform.getAuditDetails());
//status=1;
//Add customer ewallet account
updateCustomerInWalletBalance(customer, customerform.getAuditDetails());
//send sms to customer
smsManager.sendSMSToCUCustomer(customer.getMobileno(), userBean);
}
mtmrsLogger.exiting("CustomerManagerImpl", "addCustomer");

我的日志显示,程序已到达“Exiting Class: CustomerManagerImpl Method: addCustomer”这一部分。我正在保存客户,我在其他两个表中设置相同的条目。 customer表的主键是另外两张表的外键。我迷路了,请帮忙。

CREATE TABLE `CST_CUSTOMER_INFO` (
`CST_CUSTOMER_ID_PK` bigint(11) NOT NULL AUTO_INCREMENT,
`CST_MOBILE` varchar(30) DEFAULT NULL,
`CST_FIRST_NAME` varchar(50) DEFAULT NULL,
`CST_LAST_NAME` varchar(150) NOT NULL,
`CST_MIDDLE_NAME` varchar(50) DEFAULT NULL,
PRIMARY KEY (`CST_CUSTOMER_ID_PK`)
) ENGINE=InnoDB AUTO_INCREMENT=4103 DEFAULT CHARSET=latin1

我在生产中偶尔会出错,但在本地没问题..

最佳答案

由于表被多个应用程序修改,使用 @GenericGenerator(name = "generator", strategy = "increment") 将导致歧义。

解释

Strategy increment : It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. It should not be used in the clustered environment.

因此您应该重新考虑使用什么策略来生成 ID。使用 sequencenative 策略可以解决您的问题。

关于java - Hibernate 键 '7090' 的重复条目 'PRIMARY',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15759348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com