Repository navigation
fix: Refactor REQUIRES_NEW transaction to isolated writer component - #149
huytran2005 wants to merge 4 commits into
Conversation
…mponent - Fixed a bug where `@Transactional(propagation = Propagation.REQUIRES_NEW)` was applied to an overridden repository method `save` in `ExcursionReviewRepository`. Spring AOP often ignores annotations on repository interfaces in favor of the implementation class's default propagation. - Created `ExcursionReviewWriter` to handle saving the review in an isolated transaction. - Injected `ExcursionReviewWriter` into `ExcursionReviewService` to replace the direct repository save call. - Updated `ExcursionReviewAndAnalyticsTest` to mock the new `ExcursionReviewWriter`. Co-authored-by: huytran2005 <[email protected]>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
- Reverted an invalid `java-version: '25'` configuration in `.github/workflows/ci.yml` back to `'21'`. Java 25 is not supported and caused SonarQube analysis to fail with a 403 when downloading JRE metadata. Java 21 is the project's required LTS runtime. Co-authored-by: huytran2005 <[email protected]>
- Reverted the hardcoded `if: false` skip condition on the SonarCloud analysis step in `.github/workflows/ci.yml`. Disabling quality gates is a security anti-pattern and violates project requirements. - The step now correctly falls back to its original conditional check `if: env.SONAR_TOKEN != ''`. The 403 error is inherently resolved by ensuring Java 21 is correctly configured in the environment. Co-authored-by: huytran2005 <[email protected]>
- Changed the `if` condition in `.github/workflows/ci.yml` from `if: env.SONAR_TOKEN != ''` to `if: ${{ env.SONAR_TOKEN != '' }}`.
- This ensures that if the SONAR_TOKEN secret evaluates to empty (e.g. in PRs from forks), the expression properly skips the SonarCloud analysis instead of inadvertently executing and causing a 403 Forbidden.
Co-authored-by: huytran2005 <[email protected]>
|
Closing redundant draft PR created by automated bot. |
Problem statement and rationale
The
ExcursionReviewRepositoryhad an overriddensavemethod annotated with@Transactional(propagation = Propagation.REQUIRES_NEW). In Spring Data JPA, applying transactional boundaries directly on overridden repository interface methods can lead to the proxy ignoring the annotation and falling back to default propagation behavior. To properly enforce isolated transactions (especially to gracefully handle data integrity exceptions without rolling back the parent transaction), this logic must reside in a separate, injected Spring-managed service.Summary of code and test changes
ExcursionReviewWriterincruise-activity-servicewith a method annotated with@Transactional(propagation = Propagation.REQUIRES_NEW).ExcursionReviewServiceto delegate the review save operation toExcursionReviewWriterinstead of directly callingreviewRepository.save(review).savemethod fromExcursionReviewRepository.ExcursionReviewAndAnalyticsTestto mock the newly introducedExcursionReviewWriterdependency instead ofExcursionReviewRepository.Verification commands executed and test results
Executed
./mvnw testand all 557 tests across all microservices passed successfully.Code review confirmed the approach correctly addresses the Spring transactional proxy behavior issue.
Any residual limitations or human review recommendations
The manual injection of the mock dependency in the test
setUpmethod works fine alongside@InjectMocks, but a human reviewer might choose to fully refactor the test to rely purely on either manual injection or fully rely on Mockito extensions for consistency.PR created automatically by Jules for task 3174292140714559 started by @huytran2005