Skip to content

CAMEL-24132: camel-jpa - Fix medium-severity findings from component review#24794

Merged
davsclaus merged 1 commit into
mainfrom
fix/CAMEL-24132
Jul 16, 2026
Merged

CAMEL-24132: camel-jpa - Fix medium-severity findings from component review#24794
davsclaus merged 1 commit into
mainfrom
fix/CAMEL-24132

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

Summary

Fixes 5 of 6 medium-severity findings from the July 2026 camel-jpa component review (CAMEL-24132):

  • M1: receiveNoWait() no longer delegates to receive() with pessimistic locking — refactored into doReceive(boolean useLocking) so receiveNoWait() runs without locks
  • M2: receive(timeout) now calls future.cancel(true) on TimeoutException so abandoned tasks don't accumulate holding DB locks
  • M3: setLockMode() is skipped for native queries, which throw IllegalStateException per JPA spec
  • M4: Concurrent insert race in JpaMessageIdRepository.add() now catches constraint violations and maps them to return false (duplicate detected) instead of failing the exchange. Also removed premature entityManager.close() inside the transaction lambda
  • M6: isUseExecuteUpdate() now trims query strings and detects update keywords (INSERT/UPDATE/DELETE) instead of select, so queries with leading whitespace or CTEs are correctly classified

M5 (parallel EntityManager fix missing from Multicast/RecipientList/WireTap) is tracked separately in CAMEL-24174.

Test plan

  • All 96 existing camel-jpa tests pass (0 failures)
  • Manual verification of M3 with nativeQuery + default consumeLockEntity=true
  • Manual verification of M6 with leading-whitespace and CTE queries

Claude Code on behalf of davsclaus

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: CAMEL-24132 — Fix medium-severity findings from component review

Verdict: Approve

This PR addresses 5 of 6 medium-severity findings from the JPA component review. Each fix is well-targeted:

M1 — receiveNoWait() refactored (JpaPollingConsumer)
Clean refactoring into doReceive(boolean useLocking). receiveNoWait() now correctly skips pessimistic locking so it returns immediately rather than blocking on row locks.

M2 — future.cancel(true) on timeout (JpaPollingConsumer)
Previously, receive(timeout) caught TimeoutException but left the future running — meaning the submitted Callable could continue holding DB locks indefinitely. The future.cancel(true) fix correctly interrupts the abandoned task.

M3 — Skip setLockMode() for native queries (JpaPollingConsumer)
The JPA spec throws IllegalStateException when setLockMode() is called on a native query. The guard nativeQuery == null correctly prevents this, and the nativeQuery field is already defined in the class (line 53). This is consistent with the native-query guards added in PR #24793 (createDeleteHandler) and the existing lockEntity() method.

M4 — Constraint violation race handling (JpaMessageIdRepository)
Two good changes:

  • Catching SQLIntegrityConstraintViolationException / EntityExistsException and returning false (duplicate) instead of throwing is correct for concurrent insert races. Walking the cause chain handles JPA provider wrapping.
  • Removing the premature entityManager.close() inside the try block (after flush()) is correct — the finally block already handles cleanup.

M6 — isUpdateQuery() whitespace & keyword detection (JpaProducer)
Fixes leading-whitespace queries that were misclassified. The logic change from "not-SELECT → update" to "INSERT/UPDATE/DELETE → update" is more explicit. This does change behavior for CTE-based DML (WITH ... UPDATE ...) and MERGE/CALL statements, which would now default to non-update, but users can set useExecuteUpdate explicitly for those edge cases, and CTE selects (WITH ... SELECT ...) — the more common case — are now correctly handled.

Minor observations (non-blocking):

  1. FQCNs in isConstraintViolation(): java.sql.SQLIntegrityConstraintViolationException and jakarta.persistence.EntityExistsException are used as fully qualified names rather than imported. Per project conventions, these should be imported. The build's OpenRewrite rule should auto-fix this, but the formatter/impsort might not add the imports automatically.

  2. Premature entityManager.close() in remove() and clear(): The premature close-after-flush was correctly removed from add(), but the same pattern still exists in remove() (line 206) and clear() (line 256). These are benign (the finally guard prevents double-close) but inconsistent.

Reviewed with Claude Code (claude-code/1.0.3) on behalf of gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-jpa

🔬 Scalpel shadow comparison — Scalpel: 9 tested, 29 compile-only — current: 9 all tested

Maveniverse Scalpel detected 38 affected modules (current approach: 9).

⚠️ Modules only in Scalpel (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

Skip-tests mode would test 9 modules (1 direct + 8 downstream), skip tests for 29 (generated code, meta-modules)

Modules Scalpel would test (9)
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-jpa
  • camel-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
Modules with tests skipped (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (38 modules)
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Lucene (deprecated)
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: JPA
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

@davsclaus davsclaus added this to the 4.22.0 milestone Jul 16, 2026
@davsclaus davsclaus self-assigned this Jul 16, 2026
@davsclaus davsclaus added the bug Something isn't working label Jul 16, 2026
…review

- M1: receiveNoWait() no longer delegates to receive() with pessimistic locking
- M2: receive(timeout) cancels the background future on timeout
- M3: setLockMode() is skipped for native queries per JPA spec
- M4: Concurrent insert race in JpaMessageIdRepository maps constraint violation to duplicate
- M6: isUseExecuteUpdate() trims query and detects update keywords instead of select

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@davsclaus
davsclaus merged commit 9e24603 into main Jul 16, 2026
5 checks passed
@davsclaus
davsclaus deleted the fix/CAMEL-24132 branch July 16, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants