I had run into the same thing and swirled around for a long time
before figure it out, but I think it may have something to do with the
deprecation/retirement of the global alternative mechanism.  The way
that I got it to work was to write my own simple TransactionStrategy
implementation class and annotate it as an alternative with an
increased priority, something like the following:
```
@Dependent
@Alternative
@Priority(Interceptor.Priority.APPLICATION + 1)
@Default
public class MyOwnTransactionStrategy implements TransactionStrategy {

    @Serial
    private static final long serialVersionUID = 8761690854289084140L;

    @Override
    public Object execute(final InvocationContext invocationContext)
throws Exception {
        return invocationContext.proceed();
    }

}
```

I'm using Payara6 w/ CDI4 and it seems to work.  It doesn't seem to
require registering the class as an alternative in beans.xml either.

Hope that helps!
- Phillip

On Mon, Feb 5, 2024 at 4:05 PM Thomas Frühbeck <t.fruehb...@gmail.com> wrote:
>
> I have a multi-module project where I seem to be unable to switch to CMT.
> I have added the alternative definition according docs:
> <alternatives>
> <class>org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategy</class>
> </alternatives>
>
> If I @Inject TransactionStrategy in my own code, an instance of
> ContainerManagedTransactionStrategy is injected.
>
> But when the QueryHandler executes a query, it gets the ResourceLocal:
>
> Caused by: java.lang.IllegalStateException: Transaction is not accessible
> when using JTA with JPA-compliant transaction access enabled
>         at org.hibernate@6.4.2.Final
> //org.hibernate.internal.AbstractSharedSessionContract.getTransaction(AbstractSharedSessionContract.java:524)
>         at org.hibernate@6.4.2.Final
> //org.hibernate.internal.SessionImpl.getTransaction(SessionImpl.java:198)
>         at org.jboss.as.jpa@31.0.0.Final
> //org.jboss.as.jpa.container.AbstractEntityManager.getTransaction(AbstractEntityManager.java:504)
>         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>         at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
>         at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>         at org.jboss.weld.core@5.1.2.Final
> //org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
>         at org.jboss.weld.core@5.1.2.Final
> //org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:109)
>         at
> deployment.archive-web.war//org.jboss.weld.generated.proxies.persistence.EntityManager$AutoCloseable$1036303654$Proxy$_$$_WeldClientProxy.getTransaction(Unknown
> Source)
>         at
> deployment.archive-web.war//org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.getTransaction(ResourceLocalTransactionStrategy.java:368)
>         at
> deployment.archive-web.war//org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.execute(ResourceLocalTransactionStrategy.java:117)
>         at
> deployment.archive-web.war//org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner.executeTransactional(TransactionalQueryRunner.java:68)
>         at
> deployment.archive-web.war//org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner.executeQuery(TransactionalQueryRunner.java:50)
>         at
> deployment.archive-web.war//org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner$Proxy$_$$_WeldClientProxy.executeQuery(Unknown
> Source)

Reply via email to