Skip to content

FINERACT-1659: Fix optimistic locking in savings interest posting batch job#5671

Open
awaneetdecoder wants to merge 1 commit intoapache:developfrom
awaneetdecoder:FINERACT-1659-fix-optimistic-lock-savings-batch
Open

FINERACT-1659: Fix optimistic locking in savings interest posting batch job#5671
awaneetdecoder wants to merge 1 commit intoapache:developfrom
awaneetdecoder:FINERACT-1659-fix-optimistic-lock-savings-batch

Conversation

@awaneetdecoder
Copy link
Copy Markdown
Contributor

Problem

The savings interest posting batch job could post duplicate interest
when two instances ran concurrently. PR #5550 attempted a fix but
adamsaghy correctly identified there was no rollback mechanism —
version mismatch was silently skipped.

Fix

  • SQL uses WHERE id=? AND version=? to detect concurrent modification
  • version = version + 1 increments on each successful update
  • updateCounts[i] == 0 detected as concurrent modification
  • ConcurrentModificationException thrown on version mismatch
  • @transactional on postInterest() rolls back entire batch

Files Changed

  • SavingsAccountData.java — added version field
  • SavingsAccountReadPlatformServiceImpl.java — reads version from DB
  • SavingsSchedularInterestPoster.java — core fix
  • SavingsSchedularInterestPosterTest.java — unit tests
  • SavingsInterestPostingJobIntegrationTest.java — integration tests

Fixes FINERACT-1659
Supersedes PR #5550

@awaneetdecoder
Copy link
Copy Markdown
Contributor Author

I have force-pushed the fixes for the Lombok duplicate getters/setters and the Checkstyle trailing space. Could a maintainer please approve the workflows so the CI can run against the new commit? Thank you!

@adamsaghy
Copy link
Copy Markdown
Contributor

@awaneetdecoder Please review the failing checks!

@adamsaghy
Copy link
Copy Markdown
Contributor

Please run:
./gradlew spotlessApply spotbugsMain spotbugsTest checkstyleMain checkstyleTest
./gradlew --no-daemon build -x test -x cucumber -x doc

Before any PR or changes, please always run these two commands and make sure there is green build!

@awaneetdecoder awaneetdecoder force-pushed the FINERACT-1659-fix-optimistic-lock-savings-batch branch from 5fc3ca4 to b93060f Compare March 28, 2026 19:00
@awaneetdecoder
Copy link
Copy Markdown
Contributor Author

@adamsaghy I have addressed all the failing checks:

  1. Replaced ConcurrentModificationException with Spring's OptimisticLockingFailureException — this is semantically correct for optimistic locking failures, extends DataAccessException so it is caught by the existing handler in postInterest(), and satisfies SpotBugs.

  2. Removed unused mock infrastructure from the unit test — the 4 tests verify pure logic (updateCounts array checking) and have no dependency on Spring beans, so no mocks are needed.

  3. Ran both commands locallyspotlessApply spotbugsMain spotbugsTest checkstyleMain checkstyleTest and build -x test -x cucumber -x doc both passed cleanly. The :fineract-war:binaryDistTar failure is a pre-existing duplicate JAR issue reproducible on develop with no changes applied.

Thank you for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants