I'm currently implementing a solution to leverage the transactional event facilities of CDI in Java SE.
- A TransactionServices class and made sure it's loaded via the ServiceLoader
- A UserTransaction class
- A Transactional interceptor
And I have added the weld-jta module to my project.
Everything is fine until I invoke afterCompletion() of the synchronization observer.
Please note that the Transactional annotation in the example above is my interceptor binding annotation, not the JTA's one.
When afterCompletion is invoked, the transaction related to 'fireEvent' is committed. A new transaction is started when the observer method is invoked.
When the observer method returns, the later transaction (related to 'onEvent') is committed. But then, a new event is fired again and it's value is null, and in the logs I can see:
As you can see, the list of events to distribute after the completion of the first commit seems to contain some remaining of the first distributed event. Then, after the second commit, WELD tries to distribute this event again.
I had a look to the source code of weld-jta, and I can see that:
- The synchronization observer is set when an event is fired
- The synchronization observer is not cleared when a new transaction is started while an AFTER_SUCCESS event is being notified
I had a look to the CDI specifications, and I could not see anything that would explain the reason why this code should not work.
Did I misunderstand the specifications? Did I do something wrong? Or is there a bug?