Home Transaction commit error is not captured in EJB code
Reply: 0

Transaction commit error is not captured in EJB code

user6496
1#
user6496 Published in August 14, 2018, 8:27 am

When I shutdown DB after flush() and before commit(), an exception is logged but not captured by the code:

@Stateless
@TransactionAttribute(TransactionAttributeType.NEVER)
public class OuterService {

    @EJB InnerService innerService;

    public String outerMethod() {
        try {
            innerService.innerMethod();
            return "success";
        } catch (Exception e) {
            return "failure";
        }
    }
}

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class InnerService {

    @PersistenceContext EntityManager em;

    public void innerMethod() {
        em.persist(new Entity());
        em.flush();
    } //put the breakpoint here
}

I run the code in debug mode and set a breakpoint after flush but before existing the transactional method. When the execution is paused, I stop db service and then resume the code.

An exception is logged with the following root cause:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.

but it is not captured by the outer try..catch block and the method successfully completes. It seems that JTA implementation suffocates the exception. How can I be notified of an error?

I already tried BMT and CDI events but none worked. Plain JDBC and JPA (Hibernate, with built-in and C3p0 pools) in Java SE environment, however, do work.

My setup: Ubuntu 17.10, Wildfly 10, MySQL 5.7.20, Connector/J 5.1.44

Here is the log (some lines removed because of character limit):

2018-01-07 12:38:44,980 INFO  [stdout] (default task-1) Hibernate: insert into Entity values ( )
2018-01-07 12:39:06,027 WARN  [org.jboss.jca.core.connectionmanager.listener.TxConnectionListener] (default task-1) IJ000305: Connection error occured: org.jboss.jca.core.connectionmanager.listener.TxConnectionListener@f0b0aed[state=NORMAL managed connection=org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@327b7fd0 connection handles=0 lastReturned=1515316110106 lastValidated=1515316098805 lastCheckedOut=1515316124981 trackByTx=true pool=org.jboss.jca.core.connectionmanager.pool.strategy.OnePool@a4e7bad mcp=SemaphoreConcurrentLinkedQueueManagedConnectionPool@42037075[pool=TestDS] xaResource=LocalXAResourceImpl@306327f6[connectionListener=f0b0aed connectionManager=6110d60 warned=false currentXid=null productName=MySQL productVersion=5.7.20-0ubuntu0.17.10.1 jndiName=java:/datasources/TestDS] txSync=TransactionSynchronization@360457732{tx=TransactionImple < ac, BasicAction: 0:ffff7f000101:-7fd727eb:5a51e37d:1d status: ActionStatus.COMMITTING > wasTrackByTx=true enlisted=true cancel=false}]: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.Util.getInstance(Util.java:408)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
    at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1552)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnection.commit(LocalManagedConnection.java:96)
    at org.jboss.jca.core.tx.jbossts.LocalXAResourceImpl.commit(LocalXAResourceImpl.java:172)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:96)
    at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
    at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:89)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)
    at InnerService$$$view26.innerMethod(Unknown Source)
    at OuterService.outerMethod(OuterService.java:23)
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
    at OuterService$$$view33.outerMethod(Unknown Source)
    at RestManager.test(RestManager.java:112)

2018-01-07 12:39:06,032 WARN  [com.arjuna.ats.jta] (default task-1) ARJUNA016039: onePhaseCommit on < formatId=131077, gtrid_length=47, bqual_length=36, tx_uid=0:ffff7f000101:-7fd727eb:5a51e37d:1d, node_name=mypc, branch_uid=0:ffff7f000101:-7fd727eb:5a51e37d:20, subordinatenodename=null, eis_name=java:/datasources/TestDS > (LocalXAResourceImpl@306327f6[connectionListener=f0b0aed connectionManager=6110d60 warned=false currentXid=null productName=MySQL productVersion=5.7.20-0ubuntu0.17.10.1 jndiName=java:/datasources/TestDS]) failed with exception XAException.XAER_RMFAIL: org.jboss.jca.core.spi.transaction.local.LocalXAException: IJ001156: Could not commit local transaction
    at org.jboss.jca.core.tx.jbossts.LocalXAResourceImpl.commit(LocalXAResourceImpl.java:177)
    at com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource.commit(XAOnePhaseResource.java:120)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:91)
    at InnerService$$$view26.innerMethod(Unknown Source)
    at OuterService.outerMethod(OuterService.java:23)
    at OuterService$$$view33.outerMethod(Unknown Source)
    at RestManager.test(RestManager.java:112)
    at RestManager$Proxy$_$$_Weld$EnterpriseProxy$.test(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.jca.core.spi.transaction.local.LocalResourceException: Communications link failure during commit(). Transaction resolution unknown.
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnection.commit(LocalManagedConnection.java:103)
    at org.jboss.jca.core.tx.jbossts.LocalXAResourceImpl.commit(LocalXAResourceImpl.java:172)
    ... 248 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
    at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1552)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnection.commit(LocalManagedConnection.java:96)
    ... 249 more
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.327014 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO