Jakarta EE 8 JTA 事务在 2 分钟后中止

问题描述 投票:0回答:1

我正在使用 Apach Netbeans 16 和 Glassfish 6.2.5 进行开发,每次当我有一个事务需要超过 2 分钟时,事务就会中止并出现此错误:

A system exception occurred during an invocation on EJB PaiementreservationFacade, method: public java.util.List dao.PaiementreservationFacade.getPaiementreservationPortemonnaieByPersonne(java.lang.Integer,int)|#]
  jakarta.ejb.TransactionRolledbackLocalException: Client's transaction aborted
    at com.sun.ejb.containers.EJBContainerTransactionManager.useClientTx(EJBContainerTransactionManager.java:334)
    at com.sun.ejb.containers.EJBContainerTransactionManager.preInvokeTx(EJBContainerTransactionManager.java:228)
    at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:4001)
    at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1767)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:186)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:64)
    at jdk.proxy60/jdk.proxy60.$Proxy1268.getPaiementreservationPortemonnaieByPersonne(Unknown Source)
    at BusinessService.FactureManager.create(FactureManager.java:931)
    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.glassfish.exousia.AuthorizationService.lambda$invokeBeanMethod$6(AuthorizationService.java:501)
    at org.glassfish.exousia.AuthorizationService.runInScope(AuthorizationService.java:577)
    at org.glassfish.exousia.AuthorizationService.invokeBeanMethod(AuthorizationService.java:501)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:295)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4241)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:603)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:805)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:552)
    at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:72)
    at org.jboss.weld.module.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
    at jdk.internal.reflect.GeneratedMethodAccessor199.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:867)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:804)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:552)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:136)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:113)
    at jdk.internal.reflect.GeneratedMethodAccessor200.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:867)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:804)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:348)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4216)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4206)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:188)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:64)
    at jdk.proxy60/jdk.proxy60.$Proxy1444.create(Unknown Source)

我到处寻找如何增加这个时间,但不可能。

我知道异常是由

jakarta.ejb.EJBTransactionRolledbackException

发送的

我也有这个 persistence.xml :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
             version="3.0">
    <persistence-unit name="myApp" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/MyApp</jta-data-source>

    <exclude-unlisted-classes>false</exclude-unlisted-classes>
   <properties>
       <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
       <property name="hibernate.dialect.storage_engine" value="innodb"/>
       <!--<property name = "hibernate.show_sql" value = "true" />-->
       <!--<property name="hibernate.jdbc.time_zone" value="CET"/>-->
   </properties>
    </persistence-unit>
</persistence>

我尝试在我的 persistence.xml 中添加此属性:

<property name="jakarta.persistence.lock.timeout" value="1"/>
<property name="jakarta.persistence.query.timeout" value="1"/>

但没有变化...也尝试过 javax 但仍然没有任何变化...

我能做什么?有人有想法吗?

谢谢您的帮助

编辑

我还尝试在 RESTFull 请求开始时暂停:

try {
       System.out.println("Sleep starts");
       Thread.sleep(125000);
       System.out.println("Sleep ends");
   } catch (InterruptedException e) {
       e.printStackTrace();
   }

它在 125 秒内停止,这是我的代码第一次尝试对数据库执行某些操作。我收到同样的错误...我真的不知道我需要更改什么才能继续我的程序..有人有想法吗?

java jpa jakarta-ee ejb jta
1个回答
0
投票

免责声明:我从来没有使用过 glassfish,但我有大量使用 Wildfly/Jboss 服务器的经验……它们当然不一样,但实际上,它们的行为很相似,所以你知道什么在谷歌中搜索...

在本例中,我使用了关键字:“Glassfish 6.2.5 transation timeout”...我找到了以下链接:

阅读完这两个链接(我建议您也这样做)后,我认为您必须采取一些方法来配置事务的超时:一是配置他们提到的事务服务,二是(如果您使用 EJB,当然),就是创建一个

glassfish-ejb-jar.xml
,其中包含应用程序所需的超时...

您可以在以下链接

查看该文件的结构
© www.soinside.com 2019 - 2024. All rights reserved.