Search code examples
javaosgiapache-karafxa

Why am I getting "is not a NamedXAResource" in Apache Karaf 4.0.4?


I have some transactional code that worked very well in old versions of Apache Karaf. Now in Apache Karaf 4.0.4 I see a lot of exceptions.

java.lang.IllegalStateException: Cannot log transactions as org.apache.derby.jdbc.EmbedXAResource@77cbf3e5 is not a NamedXAResource.

and

org.apache.aries.transaction.manager - 1.3.0 | Please correct the integration and supply a NamedXA java.lang.IllegalStateException: Cannot log transactions as TransactionContext{transactionId=null,connection=ActiveMQConnection


Solution

  • I found the answer and post it here to give others a quicker way to solve the same problem. It took me quite a while and some help from Guillaume to figure this out.

    The geronimo transaction manager that is used in Apache Karaf inside the Aries transaction manager bundle can recover transactions. By default this feature is switched off in older karaf versions. In Apache Karaf 4.0.4 this has changed.

    The config etc/org.apache.aries.transaction.cfg contains this setting

    aries.transaction.recoverable = true
    

    It activates the recovery support. The downside of this is that all jdbc and jms Connections must then implement NamedXAResource. This is outside the standard so most jdbc and jms providers do not support this.

    The solution for ActiveMQ is to use the JCAPoolingConnectionFactory. For jdbc you can wrap your XADataSource using aries transaction jdbc. It provides a pooling support that also supports recovery.

    If you are happy with how your application worked before you can simply set the above switch back to false. The transactions will then work like in older Apache Karaf versions.