shashank created CAMEL-27284:
--------------------------------
Summary: camel-jpa - JpaMessageIdRepository: a concurrent add of
the same message id fails instead of returning false on PostgreSQL and SQL
Server
Key: CAMEL-27284
URL: https://issues.apache.org/jira/browse/CAMEL-27284
Project: Camel
Issue Type: Bug
Components: camel-jpa
Reporter: shashank
Assignee: shashank
h3. What happens
CAMEL-24132 (M4) made {{JpaMessageIdRepository.add}} return false when its
insert fails on the unique key because another caller (node, thread) inserted
the same message id at the same time. It recognises the failure only as
{{SQLIntegrityConstraintViolationException}} or {{EntityExistsException}} in
the cause chain:
# The PostgreSQL driver ({{PSQLException}}, SQLState 23505) and the SQL Server
driver (SQLState 23000) throw a plain {{SQLException}}, and Hibernate throws
its {{ConstraintViolationException}} (a {{PersistenceException}}, not an
{{EntityExistsException}}) with it as the cause, so on these databases {{add}}
throws {{PersistenceException("Something went wrong ...")}}: the duplicate
message fails (error handler, redelivery, dead letter channel) instead of being
filtered. H2, Derby, MySQL and Oracle throw the subclass, which is why the
module tests pass.
# The check is inside the transaction: when the EntityManager is the
transaction's ({{sharedEntityManager=true}}), the failed flush marks the
transaction rollback-only, so the commit throws after the catch returned false,
and {{add}} fails on every database.
{{JpaKeyValueRepository}} (CAMEL-26736) already checks the SQLState class 23
and recognises the duplicate outside the transaction.
h3. How to reproduce
{{JpaMessageIdRepositoryConcurrentInsertTest}}: the flush throws what Hibernate
throws for a PostgreSQL unique violation (ConstraintViolationException ->
SQLException state 23505): add throws; same with state 23000 (SQL Server); and
with a transaction whose commit fails after the duplicate was recognised.
h3. Fix
The SQLState class 23 counts as a constraint violation (as in
JpaKeyValueRepository), and a duplicate recognised in the transaction stays a
duplicate when the commit then fails.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)