allthingssecurity commented on PR #30531:
URL: https://github.com/apache/camel/pull/30531#issuecomment-7059399403

   Thanks for the review. Everything except the IT is in 05752446c8ce (a 
follow-up commit on top of the rebased branch).
   
   - **Class 23 covers every integrity violation** 
(`JpaMessageIdRepository.java:101` / `:133`): done in this PR, as in 
`JpaKeyValueRepository.putIfAbsent`. After a constraint violation, at the flush 
or at commit, `add` reads `(processorName, messageId)` again with a new 
EntityManager in a new transaction. It returns `false` if the row is there and 
throws otherwise, so a primary key collision now fails. A violation at the 
flush is thrown wrapped in a `PersistenceException`, with the commit failure 
suppressed if there is one, because the `UnexpectedRollbackException` has no 
cause. A violation that only comes at commit is thrown as the commit failure. 
In a caller's transaction the read again runs in that transaction. It is 
already marked for rollback, so `add` may throw there, and the caller's 
transaction fails either way. The javadoc and the guide say so.
   - **Tests** (Mockito; the read again gets a second EntityManager):
     - Duplicate with the row present returns `false` for 23505, 23000, the 
H2-style subclass, a flush violation followed by a failed commit, and a 
violation at commit. The tests also check that the read again used a new 
EntityManager, in a transaction of its own after the insert's.
     - Violation with the row absent (primary key collision) throws: at the 
flush, at the flush with a failed commit, and at commit.
     - If the read again fails, its exception is thrown with the violation 
suppressed.
     - On the first commit 9 of the 12 tests fail; the three controls pass.
   - **`isConstraintViolation` in `JpaHelper`**: moved, and both repositories 
use it.
   - **"Duplicate message detected" logged twice**: it is now logged once, 
after the read again.
   - **Upgrade guide**: added "camel-jpa - JpaMessageIdRepository: add after a 
constraint violation" after the `JpaKeyValueRepository` note. It says that 
`add` now returns `false` where it threw on PostgreSQL and SQL Server (and with 
`sharedEntityManager=true` on any database), and that it still throws for other 
violations, including on H2, Derby, MySQL and Oracle, which returned `false` 
for any violation before.
   - **PostgreSQL IT**: not added. I cannot run Docker or ITs where I work, so 
I could not check that it passes. I can add it in a follow-up PR if you want it.
   
   Runs (offline, Hibernate 7.4.12): camel-jpa module tests 168 run, 0 failures 
(`JpaRouteSkipLockedEntityTest` is `@Disabled`); the new test class 20 times in 
one JVM, 240 of 240. The PR description is updated.
   
   _Claude Code on behalf of allthingssecurity_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to