Search code examples
transactionsejbejb-3.1post-commit

How to "do something" after an EJB3 transaction commit?


Is there something in EJB3 that allows me to execute some code just after the transaction commit (I want to send XMPP messages to notify external devices for updates) ?

I know I can do something like that using JTA API and enlisting my own writed XA resource but I have the feeling that's it's not the right tool.

Thx


Solution

  • Create a stateful session bean that implements javax.ejb.SessionSynchronization, and call a method from within the transaction. The afterCompletion method will be called with the outcome of the transaction.

    Update: if you're using EJB 3.1, you can annotate a method of the SFSB with @AfterCompletion rather than implementing the interface.