Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: Two EJB Instances Without Extended Persistence Contexts Leading to Transaction Exception #6983

Closed
tiagomistral opened this issue Sep 30, 2024 · 1 comment
Assignees
Labels
Status: Open Issue has been triaged by the front-line engineers and is being worked on verification Type: Bug Label issue as a bug defect

Comments

@tiagomistral
Copy link

tiagomistral commented Sep 30, 2024

Brief Summary

I am experiencing an issue while working with a REST endpoint that involves a mix of Stateful EJBs and a Singleton EJB, specifically concerning the transaction propagation and extended persistence contexts.

Throughout the entire flow from the REST endpoint to the second Stateful EJB, there is no reference to the PersistenceContext that is defined in a separate Stateful EJB. The setup involves two Stateful EJBs and one Singleton EJB, but none of these EJBs directly interact with or utilize the PersistenceContext from the EntityManagerAwareStateful EJB, which is defined alongside them.

The following exception is thrown:

javax.ejb.EJBException: Detected two different extended persistence contexts for the same EntityManagerFactory within a transaction
	at com.sun.ejb.containers.StatefulSessionContainer.validateEMForClientTx(StatefulSessionContainer.java:2549)
	at com.sun.ejb.containers.EJBContainerTransactionManager.useClientTx(EJBContainerTransactionManager.java:348)
	at com.sun.ejb.containers.EJBContainerTransactionManager.preInvokeTx(EJBContainerTransactionManager.java:238)
	at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:4563)

Expected Outcome

I expect that when the GET method on the REST endpoint is called, the transaction is managed correctly across the EJBs, allowing for the use of the EntityManagerFactory without encountering conflicts from multiple extended persistence contexts.

Current Outcome

Instead of the expected behavior, an exception is thrown indicating that two different extended persistence contexts are detected within the same transaction. This suggests that the MyFirstStateful EJB and the MySecondStateful EJB may be creating separate contexts when they should be sharing the same one.

Reproducer

  1. The REST endpoint is defined as follows:
@Path("bug")
public class Rest {

    @Inject
    private MyFirstStateful firstStateful;

    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public String get() {
        return firstStateful.invoke();
    }
}
  1. The MyFirstStateful EJB invokes a method on the MySingleton EJB:
@Stateful
public class MyFirstStateful {

    @Inject
    private MySingleton singleton;

    public String invoke() {
        return singleton.invoke();
    }
}

  1. The MySingleton EJB is configured as follows:
@Singleton
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class MySingleton {

    public static final String EJB_NAME = "my-ejb";

    @Inject
    private MySecondStateful secondStateful;

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public String invoke() {
        return secondStateful.invoke();
    }
}
  1. The MySecondStateful EJB:
@Stateful(name = "myStateful")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class MySecondStateful {

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public String invoke() {
        return "bug";
    }
}

  1. Additionally, there is another Stateful EJB that is intended to be aware of the EntityManagerFactory:
@Stateful
@Named("emAwareStateful")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class EntityManagerAwareStateful {

    @PersistenceContext(unitName = "DummyPU", type = PersistenceContextType.EXTENDED)
    private EntityManagerFactory emf;

}

payara-issue.zip

Operating System

6.10.6-10-MANJARO

JDK Version

JDK 8 + payara 5.2020.2

Payara Distribution

Payara Server Full Profile

@tiagomistral tiagomistral added Status: Open Issue has been triaged by the front-line engineers and is being worked on verification Type: Bug Label issue as a bug defect labels Sep 30, 2024
@tiagomistral tiagomistral changed the title Bug Report: Two Extended Persistence Contexts Detected Within a Propagated Transaction Bug Report: Two EJB Instances Without Extended Persistence Contexts Leading to Transaction Exception Sep 30, 2024
@felixif
Copy link

felixif commented Oct 7, 2024

Hello @tiagomistral,

We are no longer supporting Payara 5 Community Edtion, we are currently only accepting bug reports that can be reproduced in the latest Payara 6 Community version, 6.2024.9. If your bug is relevant to Payara 6 Community, please do submit another issue with a reproducer converted for Jakarta EE 10.

Best regards,
Felix

@felixif felixif closed this as completed Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Open Issue has been triaged by the front-line engineers and is being worked on verification Type: Bug Label issue as a bug defect
Projects
None yet
Development

No branches or pull requests

2 participants