Sonu Agarwal
Sonu Agarwal

Reputation: 117

JpaItemWriter MultiThreader Primary Key Violation

I am using jpaItemWriter with Multi Threading. But i keep getting SQL Error: 1062, SQLState: 23000 Primary Key Violation.Although i am fetching distinct records and inserting the same. Is JpaItemWriter ThreadSafe.? In multi threading how to make Processor and writer thread safe,in order to avoid exceptions like above. Some times i also get the below Exception

java.sql.SQLException: Deadlock found when trying to get lock; try restarting transaction
o.h.e.jdbc.batch.internal.BatchingBatch  : HHH000315: Exception executing batch [java.sql.BatchUpdateException: (conn=629417) Duplicate entry 

Thanks in Advance

Upvotes: 0

Views: 439

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31600

Yes, the JpaItemWriter is thread-safe (As mentioned in the Javadoc).

Using a multi-threaded step with database readers and writers is not the best option, I recommend using a partitioned step instead.

Upvotes: 1

Related Questions