You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 7 Members of 6388 |
| Forum: Seam Users |
01. Dec 2008, 22:13 CET | Link |
I have an MDB that is a component and it calls SLSBs that are also components. When the SLSBs have a seam managed entityManager I am getting the following exception.
2008-12-01 14:50:59,029 ERROR [org.jboss.seam.transaction.SynchronizationRegistry] Exception processing transaction Synchronization after completion java.lang.IllegalStateException: No event context active at org.jboss.seam.ScopeType.getContext(ScopeType.java:114) at org.jboss.seam.Component.getInstance(Component.java:1956) at org.jboss.seam.Component.getInstance(Component.java:1951) at org.jboss.seam.Component.getInstance(Component.java:1924) at org.jboss.seam.Component.getInstance(Component.java:1919) at org.jboss.seam.transaction.Transaction.instance(Transaction.java:36) at org.jboss.seam.persistence.ManagedPersistenceContext.close(ManagedPersistenceContext.java:191) at org.jboss.seam.persistence.ManagedPersistenceContext.afterCompletion(ManagedPersistenceContext.java:180) at org.jboss.seam.transaction.SynchronizationRegistry.afterTransactionCompletion(SynchronizationRegistry.java:42) at org.jboss.seam.transaction.EjbSynchronizations.afterCompletion(EjbSynchronizations.java:80) at org.jboss.ejb3.stateful.SessionSynchronizationInterceptor$SFSBSessionSynchronization.afterCompletion(SessionSynchronizationInterceptor.java:87) at org.jboss.tm.TransactionImpl.doAfterCompletion(TransactionImpl.java:3109) at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:1294) at org.jboss.tm.TxManager.commit(TxManager.java:588) at org.jboss.jms.asf.StdServerSession$TransactionDemarcation.end(StdServerSession.java:503) at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:219) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756) at java.lang.Thread.run(Thread.java:595)
This looks like a bug, because the managed persistence context says that the contexts will already be destroyed by this point.
public class ManagedPersistenceContext
...
public void afterCompletion(int status)
{
synchronizationRegistered = false;
//if ( !Contexts.isConversationContextActive() )
if (destroyed)
{
//in calls to MDBs and remote calls to SBs, the
//transaction doesn't commit until after contexts
//are destroyed, so wait until the transaction
//completes before closing the session
//on the other hand, if we still have an active
//conversation context, leave it open
close();
}
}
However, on close it immediately tries to get the Transaction from the event scope and fails.
public class Transaction
{
public static UserTransaction instance()
{
return (UserTransaction) Component.getInstance(Transaction.class, ScopeType.EVENT);
}
Am I doing something wrong or is this a bug?
Still not sure if this is a bug or not, but wrapping the isActive call with an isEventContextActive() solved the issue.
public class ManagedPersistenceContext ... private void close() { if (Contexts.isEventContextActive()) { boolean transactionActive = false; try { transactionActive = Transaction.instance().isActive(); } catch (SystemException se) { log.debug("could not get transaction status while destroying persistence context"); } if ( transactionActive ) { throw new IllegalStateException("attempting to destroy the persistence context while an active transaction exists (try installing <transaction:ejb-transaction/>)"); } } if ( log.isDebugEnabled() ) { log.debug("destroying seam managed persistence context for persistence unit: " + persistenceUnitJndiName); } if (entityManager!=null && entityManager.isOpen()) { entityManager.close(); } }https://jira.jboss.org/jira/browse/JBSEAM-3778
Is somebody working on this? I believe I have the same situation when asynchronous method on SLSB is executed using EJB timer service.