The EJB container cannot complete a transaction after a method annotated with @Asynchronous was invoked. It claims that the JDBC managed connection is not valid:
The database used is Derby. The complete exception stack trace can be found among the attachments, as well as a sample web application illustrating this issue. The configuration of JDBC connection pool is among the attachments as well. However, the error does not occur at all times.
The scenario description is the following (however, it may take some time to reproduce the issue):
- the test application is deployed
- in the web form of the test application:
- click Run method button - the method executes asynchronously, it waits for one minute and then persists a sample JPA entity
- click Get results button - in roughly 1 of 10 cases the exception is thrown; if the exception does not appear, wait for some time before clicking the Get results button.
The exception is often thrown after some (not regular) time period. It seems that it is the most likely to happen when the first action after deployment is hitting the Run method button (i.e. not getting the results from database before calling the asynchronous method).
In real application, when the user started some asynchronous process and after some time (e.g. 5 minutes) the user wants to retrieve the results from the database. It looks like a JDBC connection has timed-out. We have run into this only when using @Asynchronous methods with the default TransactionAttribute (REQUIRED which should behave as REQUIRES_NEW with asynchronous methods) settings.
The EJB used in the test looks as follows:
Are there any limitations when using transactional access to JPA entities in @Asynchronous methods?