CAMEL-24131: camel-jpa - Guard consumeDelete handler against Object[] from native queries#24793
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
… from native queries Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
f7afbbc to
fbc601b
Compare
gnodet
left a comment
There was a problem hiding this comment.
Review: CAMEL-24131 — Guard consumeDelete handler against Object[] from native queries
Verdict: Approve ✅
The fix adds a type guard to the default consumeDelete handler in createDeleteHandler(), preventing em.remove() from being called on Object[] results (which aren't managed JPA entities).
Why this is correct:
When using nativeQuery without resultClass, JPA returns Object[] rows. Calling em.remove() on an Object[] throws IllegalArgumentException because it's not a managed entity. This causes the row to be reprocessed on every poll — an infinite reprocessing loop.
The guard follows the established precedent in the same class:
lockEntity()(line 377) already usesentity.getClass().isArray()to handle native query results, with aTODOcomment acknowledging the native query limitation- The new guard mirrors this pattern exactly
The warning message is well-crafted — it tells the user both how the problem arose (native query without resultClass) and the two concrete remediation options (consumeDelete=false or configure resultClass).
Edge cases handled:
nullentityBean → guarded withentityBean != nullcheck, logged as type "null"Object[]→isArray()catches it, log shows the actual class name
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.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 tested, 29 compile-only — current: 9 all testedMaveniverse Scalpel detected 38 affected modules (current approach: 9).
|
Summary
When a JPA consumer uses
nativeQuerywithoutresultClass, results are returned asObject[]. The defaultconsumeDelete=truehandler callsem.remove(entityBean)unconditionally, which throwsIllegalArgumentExceptiononObject[]since it's not a managed entity. This causes the row to never be deleted and reprocessed on every poll — an infinite reprocessing loop.Fix
Added an array type guard to the
consumeDeletehandler, matching the pattern already used bylockEntity()(line 376) which anticipatesObject[]from native queries. When the entity bean is an array, the delete is skipped and a WARN log is emitted advising the user to setconsumeDelete=falseor configure aresultClass.Claude Code on behalf of davsclaus