javacdideltaspikeweld-se

Deltaspike TransactionStrategy Alternative Ambiguous dependencies


I'm defining the TransactionStrategy in apache-deltaspike.properties, using Global Alternatives configuration:

globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy

My beans.xml has the deltaspike-data module Interceptor only:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                           http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.1" bean-discovery-mode="all">
    <interceptors>
        <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
    </interceptors>
</beans>

But I'm being hit by the exception below, which doesn't make any sense to me:

WELD-001409: Ambiguous dependencies for type TransactionStrategy with qualifiers @Default
  at injection point [UnbackedAnnotatedField] @Inject private org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.transactionStrategy
  at org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.transactionStrategy(TransactionalInterceptor.java:0)
  Possible dependencies: 
  - Managed Bean [class org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy] with qualifiers [@Any @Default],
  - Managed Bean [class org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy] with qualifiers [@Any @Default]

Apparently the BeanManagedUserTransactionStrategy alternative is being activated by default. Cause when I remove the Global alternative definition I can see that deltaspike-data module uses the BeanManagedUserTransactionStrategy.

Dependencies Versions:

Any ideas of how to get around it? I need to use the ResourceLocalTransactionStrategy.


Solution

  • I'm using a work-around: excluding the BeanManagedUserTransactionStrategy from the beans scan.

    I'm doing this in beans.xml using the WELD specific XML schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:weld="http://jboss.org/schema/weld/beans">
        <weld:scan>
            <weld:exclude name="org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy"/>
        </weld:scan>
        <interceptors>
            <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
        </interceptors>
    </beans>
    

    By doing this I'm giving up on portability, meaning this will only work with WELD.