spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

JpaPagingItemReader invokes tx.begin() on active transactions [BATCH-1927]

Open spring-projects-issues opened this issue 12 years ago • 1 comments
trafficstars

David Zeigler opened BATCH-1927 and commented

In JpaPagingItemReader, a new transaction is started in the doReadPage method. If an exception is thrown between starting the transaction and committing the transaction, the record is skipped. Then when the next record is processed, tx.begin() will throw an exception because the EntityManager's transaction is active.

One way to reproduce this is by adding an invalid parameter name to queryParameters (one that is not mapped in the queryString). query.setParameter will throw an IllegalArgumentException resulting in the first record being skipped. The next time doReadPage is invoked, the transaction is still active since the tx.commit() was bypassed and there was no tx.rollback(). tx.begin() will throw an IllegalArgumentException because the transaction is already active.

When an exception is thrown prior to tx.commit(), the transaction should be rolled back.


Affects: 2.1.9

2 votes, 3 watchers

spring-projects-issues avatar Dec 12 '12 14:12 spring-projects-issues

Thank you for opening the issue. Can you retry with the latest release of Spring Batch and report back the results?

cppwfs avatar Jul 17 '23 13:07 cppwfs