Reputation: 197
I have a problem with executing large number of queries.
I need to execute more than 10, 000 native sql queries within a single transaction. These queries are generated dynamically and cached in the system. After completion of query generation, those are sent and are executed one by one, within a single transaction. The application is developed using EJB 3 and its running on JBoss 5.1.
The application works fine if the number of queries are less than 7200 (approximate value). But if there are more queries than this, the method throws and EJB exception and the transaction is rolled back. No data gets persisted.
This is the place where rolling back happens. [Only if number of queries are more than 7200]
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void confirmOrder(String[] queries) {
for (int i = 0; i < queries.length; i++) {
em.createNativeQuery(queries[i]).executeUpdate(); //line # 108
}
BigInteger bigInt = (BigInteger)em.createNativeQuery("select max(id) from order_item").getSingleResult();
return bigInt!=null ? Long.valueOf(bigInt.longValue()) : null;
}
Is there a way to increase number of queries that can be executed within a transaction? Please make your suggestions on this.
/Viraj
The following is the error trace.
17:36:33,233 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3a3 in state RUN
17:36:33,238 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_7] - TransactionReaper::doCancellations worker Thread[Thread-10,5,jboss] successfully canceled TX -3f57767b:bc55:4fd9d129:e3a3
17:36:33,635 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3bf in state RUN
17:36:33,636 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] - Abort of action id -3f57767b:bc55:4fd9d129:e3bf invoked while multiple threads active within it.
17:36:33,636 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] - CheckedAction::check - atomic action -3f57767b:bc55:4fd9d129:e3bf aborting with 1 threads active!
17:36:34,135 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3bf in state CANCEL
17:36:34,635 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3bf in state CANCEL_INTERRUPTED
17:36:34,636 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_6] - TransactionReaper::check worker Thread[Thread-10,5,jboss] not responding to interrupt when cancelling TX -3f57767b:bc55:4fd9d129:e3bf -- worker marked as zombie and TX scheduled for mark-as-rollback
17:36:34,636 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_11] - TransactionReaper::check failed to mark TX -3f57767b:bc55:4fd9d129:e3bf as rollback only
17:36:34,904 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@5a720719
17:36:34,926 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_13] - TransactionReaper::doCancellations worker Thread[Thread-10,5,jboss] missed interrupt when cancelling TX -3f57767b:bc55:4fd9d129:e3bf -- exiting as zombie (zombie count decremented to 0) ........
......
17:36:34,935 ERROR [CardOrderCreateFacadeBean] Confirming order is failed.
javax.ejb.EJBTransactionRolledbackException: Executing an update/delete query
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
........................
...............
Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:48)
at rk.ejb.eao.OrderEAOImpl.confirmOrder(OrderEAOImpl.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76)
at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62)
at sun.reflect.GeneratedMethodAccessor358.invoke(Unknown Source)
........
.......
Upvotes: 2
Views: 22606
Reputation: 197
You can increase transaction time out globally or at method level according to your requirement.
< property name="transactionTimeout"> 1200 < /property >
For more information: https://community.jboss.org/wiki/TransactionTimeout
Upvotes: 7
Reputation: 197
I was able to resolve this issue. Though it shows an exception like this, this happens due to rolling back of the transaction. The exact reason for rolling back of the transaction is time out of the transaction. When there are large number of queries to be executed, transaction is timed out and ultimate result is the above exception. Making changes in the JBoss transaction configurations, eliminated the error.
Upvotes: 5