I am having a problem with EJB components that are responsible for starting a transaction. I am using Jboss 5.01.
Basically I would like to execute a given code after a specific transaction was committed. the specific code also involves calling an EJB component which makes it's own transactions.
To make sure that my code is executed after a previous transaction is committed I've registered a Synchronization component into a transaction component :
Transaction tx = transactionManager.getTransaction();
tx.registerSynchronization(new CallbackSynchronization());
The Synchronizaton
implementation basically does the following:
class CallbackSynchronization implements Synchnronization {
private AccountService service; // This is a Stateless session bean
public CallbackSynchronization(AccountService service) {
this.service = service;
}
public afterCompletion(int status) {
if(Status.STATUS_COMMITTED == status) {
service.deleteAccounts();
}
}
}
Problem is that when I call the service.deleteAccounts()
I get an exception that eventually tells me that the transaction is not active.
And this is what confuses me. an EJB with methods marked with @TransactionAttribute(TransactionAttributeType.REQUIRED)
will create a new transaction if one is not active(the REQUIRED is the default in JBOSS).
Why then am I getting "Transaction not active" ?
Many Thanks,
Yaniv