Technology stack: openJdk17 Spring Batch 5 Spring Boot 3 Spring data Jpa 3 Hiberante 6.4

My Entity : @Entity @Table(name = "CMN_TXN_DATA") public class TransactionEntity {

@Column(name = "ID_SGK")
@Id
@SequenceGenerator(name = "cmnTxnSeqGenerator", sequenceName = "CMN_TXN_ID_SEQ")
@GeneratedValue(strategy = SEQUENCE, generator = "cmnTxnSeqGenerator")
private Long cmnTxnSgk;

@Column(name = "WF_EXEC_ID")
private Long executionId;

}

This is database seuence CMN_TXN_ID_SEQ.

Usecase : While running the job , job will read the data from one table and insert into another table.

****Bulk insert : transactionRepository.saveAll(chunk.getItems()) **is failing ******

Error: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session

Try with @SequenceGenerator(name = "cmnTxnSeqGenerator", sequenceName = "CMN_TXN_ID_SEQ", allocationSize = 1) But with allocationSize , batch insert is not working. For 1000 records its taking 6 minutes to insert. And if we remove allocationSize = 1, the below error is coming :

org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session

0

There are 0 best solutions below