jungm opened a new pull request, #3063:
URL: https://github.com/apache/tomee/pull/3063

   [TOMEE-4727](https://issues.apache.org/jira/browse/TOMEE-4727): a Jakarta 
Data repository called from a CDI `@Observes(during = AFTER_SUCCESS)` observer 
fails with `DataException: Transaction ... is not active`.
   
   ## Summary
   
   After success observers run in `afterCompletion`, where the committed 
transaction is still bound to the thread with status `STATUS_COMMITTED`. 
`RepositoryInvocationHandler.executeInTransaction` joined it because it only 
checked for `STATUS_NO_TRANSACTION`. [Jakarta Data 1.0 
ยง7.3](https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0#_jakarta_transactions)
 only requires joining an *active* transaction.
   
   ```diff
    executeInTransaction
   -  if status == NO_TRANSACTION
   -    begin
   -  else
   -    join bound transaction
   +  if status is ACTIVE or MARKED_ROLLBACK
   +    join bound transaction
   +  else
   +    if a transaction is bound (completing / completed)
   +      suspend it
   +    begin
      run operation
      commit what we began
   +  resume the suspended transaction
   ```
   
   ## Evidence
   
   `JakartaDataTransactionalTest.findInsideAfterSuccessObserver`:
   
   ```text
   @Transactional insertAndNotify("tx-observed")   // fires ItemInserted
     AFTER_SUCCESS observer -> repository.findById(id)
   assert observer saw no exception and label == "tx-observed"
   ```
   
   - **Before:** `AssertionError: Repository call in the observer failed: 
jakarta.data.exceptions.DataException: Transaction 
org.apache.geronimo.transaction.manager.TransactionImpl@4b3b2a4f is not active`
     **After:** `arquillian-tomee-data-tests`: `Tests run: 9, Failures: 0, 
Errors: 0, Skipped: 0`; `openejb-jakarta-data`: `Tests run: 183, Failures: 0, 
Errors: 0, Skipped: 0`
   
   ## Merge Danger
   
   **Door:** two-way
   
   A single method in `openejb-jakarta-data`; reverting restores the old 
behaviour.
   
   **Blast Radius:** narrow
   
   Only repository calls made while the bound transaction is neither active nor 
marked for rollback change behaviour; those failed before. Calls inside an 
active transaction and calls without one take the same path as before.
   


-- 
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