spring-projects / spring-projects/spring-batch
JpaPagingItemReader invokes tx.begin() on active transactions [BATCH-1927]
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in JpaPagingItemReader.doReadPage and trace the transaction started around the queryParameters handling. Reproduce the failure with an invalid query parameter name, then verify that an exception before commit leaves no active transaction for the next read.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100