1

In my wildfly swarm application I would like to use deltaspike with the data module, JPA and JTA.

I have defined my beans.xml as this to use EnvironmentAwareTransactionStrategy as TransactionStrategy.

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<alternatives>
    <class>org.apache.deltaspike.jpa.impl.transaction.EnvironmentAwareTransactionStrategy</class>
</alternatives>

However when I run my app this exception is thrown:

at org.hibernate.jpa.spi.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:1333)
at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.getTransaction(ResourceLocalTransactionStrategy.java:372)
at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.rollbackAllTransactions(ResourceLocalTransactionStrategy.java:338)
at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.execute(ResourceLocalTransactionStrategy.java:155)
at org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.executeInTransaction(TransactionalInterceptor.java:57)

CDI used the default TransactionStrategy (ResourceLocalTransactionStrategy) instead of the alternative one (EnvironmentAwareTransactionStrategy) defined in my beans.xml.

The file beans.xml is well located in src/main/resources/META-INF and in my pom.xml I have

    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>datasources</artifactId>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>cdi</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.core</groupId>
        <artifactId>deltaspike-core-api</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.core</groupId>
        <artifactId>deltaspike-core-impl</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-data-module-api</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-data-module-impl</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-jpa-module-api</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-jpa-module-impl</artifactId>
        <scope>runtime</scope>
    </dependency>

How can I do this?

cigien
  • 57,834
  • 11
  • 73
  • 112

2 Answers2

0

I managed to make it works by following the example available here: https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/jaxrs/jaxrs-deltaspike-data

I have made the following action:

1/ removed alternatives in beans.xml

2/ add apache-deltaspike.properties in src/main/resources/META-INF containing globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategy

cigien
  • 57,834
  • 11
  • 73
  • 112
  • Weld differentiates each bean archive, effectively your WAR file and every JAR file. When you declare a global alternative, you're forcing deltaspike to override the beans actually resolved to only consider the global alternative. The alternative would only be considered for your WAR file, not the related JARs. – John Ament Feb 02 '18 at 00:48
  • If you enable your alternatives using `@Priority` (e.g. globally) instead of in `beans.xml` (per bean archive) it should work just as well. Weld isolates interceptor/decorators/alternatives enabled via `beans.xml` to just that one archive, other archives still see them as disabled unless they have the same entry in their own `beans.xml`. – Siliarus Feb 02 '18 at 07:32
  • Same thread about my question on jboss developer: https://developer.jboss.org/thread/229780 however It seems to be an expected case. But I don't understand why It can't be possible to Produce an Alternative bean for a jar dependancy. – Damien ClmntdHrt Feb 11 '18 at 02:02
0

Deltaspike gives use more explainations:

https://deltaspike.apache.org/documentation/jpa.html

In case of some versions of Weld - including several versions of JBoss EAP/Wildfly and Websphere Liberty Profile - or OpenWebBeans in BDA mode - which is not the default one, you have to configure it as a global alternative instead of an alternative in beans.xml

and

https://deltaspike.apache.org/documentation/spi.html#GlobalAlternative

They propose to use the apache-deltaspike.properties as a workaround.