我在使用Spring Boot和Hibernate时遇到问题。我在mysql表中有一个实体。当我单独致电服务时,一切正常。但是,当我使用jmeter之类的负载测试运行此程序时,出现以下错误:
org.hibernate.HibernateException: identifier of an instance of com.kafka.adapter.entity.TransactionEntity was altered from 4820 to 4821
我尝试了多种方法来获取无法成功的主键:
application.yml
server:
port: 9027
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useSSL=false&allowPublicKeyRetrieval=true
username: --
password: --
driver-class-name: com.mysql.cj.jdbc.Driver
tomcat:
test-while-idle: true
validation-query: SELECT 1
initialization-mode: never
platform: mysql
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
hibernate:
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
ddl-auto: validate
TransactionEntity:
@Entity
@Table(name = "transactions")
public class TransactionEntity {
@Id
@GeneratedValue(
strategy= GenerationType.AUTO,
generator="native"
)
@GenericGenerator(
name = "native",
strategy = "native"
)
private Long id;
private String hogan_co;
public Long getId() {
return id;
}
public void setId(Long ID) {
this.id = ID;
}
Service class
public void transactionTranslation2() {
startTimeDuration = System.currentTimeMillis();
transactionRepository.save(te);
endTimeDuration = System.currentTimeMillis();
}
public void findCategory() {
te = new TransactionEntity();
transactionTranslation2();
duration = endTimeDuration - startTimeDuration;
// System.out.println(duration * 0.001 + " seconds");
}
我期望每小时超过100万笔交易,因此它需要处理高负载。你能帮我吗?