2 Replies Latest reply on Oct 2, 2018 3:23 PM by brunosilva.codiub

    WildFly 12 & 13 - First transaction access is not active

    brunosilva.codiub

      Hi all,

       

      We're facing the following scenario in a project, where we need multiple datasources with JTA. The project uses CDI, Spring Data JPA and JSF 2.3.

       

      Project configurations:

       

      We use the <property name="wildfly.jpa.default-unit" value="true" /> configuration to set multiple datasources at the same persistence.xml.

       

      <persistence-unit name="prod-pmu" transaction-type="JTA">
           <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
           <jta-data-source>java:/rh-internet-pmu</jta-data-source>
      
           <exclude-unlisted-classes>false</exclude-unlisted-classes>
      
          <properties>
         
               <property name="wildfly.jpa.default-unit" value="true" />
      
               <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
               <property name="hibernate.default_schema" value="DBO_RH_INTERNET" />
               <property name="hibernate.format_sql" value="true" />
               <property name="hibernate.show_sql" value="true" />
               <property name="hibernate.bytecode.use_reflection_optimizer" value="true" />
               <property name="hibernate.temp.use_jdbc_metadata_defaults" value="true" />
              
          </properties>
         
      </persistence-unit>
      
      <persistence-unit name="prod-codau" transaction-type="JTA">
           <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
           <jta-data-source>java:/rh-internet-codau</jta-data-source>
      
           <exclude-unlisted-classes>false</exclude-unlisted-classes>
      
          <properties>
         
               <property name="wildfly.jpa.default-unit" value="false" />
      
               <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
               <property name="hibernate.default_schema" value="DBO_RH_INTERNET" />
               <property name="hibernate.format_sql" value="true" />
               <property name="hibernate.show_sql" value="true" />
               <property name="hibernate.bytecode.use_reflection_optimizer" value="true" />
               <property name="hibernate.temp.use_jdbc_metadata_defaults" value="true" />
              
          </properties>
         
      </persistence-unit>
      
      

       

      CDI to produce the corresponding datasource.

       

      @ProdDatabase
      public class ProdDataSourceProducer {
      
      
          @Inject
          EmpresasBean empresasBean;
          
          @Default
          @PersistenceContext(unitName = "prod-pmu")
          EntityManager entityManagerProdPMU;
          
          @Alternative
          @PersistenceContext(unitName = "prod-codau")
          EntityManager entityManagerProdCODAU;
          
          @Produces
          @RequestScoped
          public EntityManager createEntityManager() {
              EntityManager entityManager = null;
              
              EmpresasDto empresasDto = empresasBean.getEmpresasDto();
              
              if (empresasDto == null || empresasDto.getSigla() == null) 
                  entityManager = entityManagerProdPMU;
              else if (empresasDto.getSigla().equals(EmpresasEnum.PMU.name()))
                  entityManager = entityManagerProdPMU;
              else if (empresasDto.getSigla().equals(EmpresasEnum.CODAU.name()))
                  entityManager = entityManagerProdCODAU;
              
              return entityManager;
          }
          
      }

       

      Spring Data JPA Repository for querying.

       

      @Dependent
      public interface VwrhSadiLoginRepository extends JpaRepository<VwrhSadiLogin, VwrhSadiLoginId> {
           Optional<VwrhSadiLogin> findByIdEmpresaAndIdMatriculaAndCpfAndSenha(Integer empresa, Long matricula, Long cpf, String senha);
      }
      

       

      CDI on service layer.

       

      @RequestScoped
      public class VwrhSadiLoginService {
      
       @Inject
       VwrhSadiLoginRepository vwrhSadiLoginRepository;
      
       @Transactional(rollbackOn = Exception.class)
       public List<VwrhSadiLogin> findAll() throws Exception {
           return vwrhSadiLoginRepository.findAll();
       }
      
       @Transactional(rollbackOn = Exception.class)
       public boolean auth(VwrhSadiLoginDto vwrhSadiLoginDto) throws Exception {
           boolean authentication = false;
           
           Optional<VwrhSadiLogin> vwrhSadiLogin = vwrhSadiLoginRepository
                .findByIdEmpresaAndIdMatriculaAndCpfAndSenha(vwrhSadiLoginDto.getIdEmpresa(), 
                     vwrhSadiLoginDto.getIdMatricula(), 
                     vwrhSadiLoginDto.getCpf(), 
                     vwrhSadiLoginDto.getSenha());
      
           if (vwrhSadiLogin.isPresent()) {
      
                vwrhSadiLoginDto = Mapper.map(vwrhSadiLogin.get(), VwrhSadiLoginDto.class);
                vwrhSadiLoginDto.setSenha(null);
      
                authentication = true;
           } else {
                authentication = false;
           }
           
            return authentication;
        }
      
      }     
      

       

      The error happens only at the first attempt to get database access, after that everything works normally.

      The database for both datasources is the Oracle 11g.

       

       

      SQL Error: 0, SQLState: null

      javax.resource.ResourceException: IJ000460: Error checking for a transaction

      javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection

      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149)

      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)

      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1515)

      at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1554)

      at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:108)

      at org.jboss.as.jpa.container.TypedQueryNonTxInvocationDetacher.getSingleResult(TypedQueryNonTxInvocationDetacher.java:69)

      at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:214)

      at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91)

      at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136)

      at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125)

      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590)

      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578)

      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

      at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)

      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

      at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)

      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

      at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)

      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

      at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)

      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

      at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:99)

      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)

      at com.sun.proxy.$Proxy121.findByIdEmpresaAndIdMatriculaAndCpfAndSenha(Unknown Source)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      at java.lang.reflect.Method.invoke(Method.java:498)

      at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)

      at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:106)

      at br.com.codiub.rh.model.repository.JpaRepository$VwrhSadiLoginRepository$1018594886$Proxy$_$$_WeldClientProxy.findByIdEmpresaAndIdMatriculaAndCpfAndSenha(Unknown Source)

      at br.com.codiub.rh.model.service.VwrhSadiLoginService.auth(VwrhSadiLoginService.java:31)

      at br.com.codiub.rh.model.service.VwrhSadiLoginService$Proxy$_$$_WeldSubclass.auth$$super(Unknown Source)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      at java.lang.reflect.Method.invoke(Method.java:498)

      at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51)

      at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)

      at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:174)

      at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:53)

      at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:88)

      at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:47)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      at java.lang.reflect.Method.invoke(Method.java:498)

      at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)

      at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)

      at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)

      at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)

      at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)

      at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)

      at br.com.codiub.rh.model.service.VwrhSadiLoginService$Proxy$_$$_WeldSubclass.auth(Unknown Source)

      at br.com.codiub.rh.model.service.VwrhSadiLoginService$Proxy$_$$_WeldClientProxy.auth(Unknown Source)

      at br.com.codiub.rh.sadi.bean.LoginBean.login(LoginBean.java:46)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      at java.lang.reflect.Method.invoke(Method.java:498)

      at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)

      at com.sun.el.parser.AstValue.invoke(AstValue.java:289)

      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)

      at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)

      at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)

      at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)

      at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)

      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)

      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)

      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

      at org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:46)

      at javax.faces.component.UICommand.broadcast(UICommand.java:330)

      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:870)

      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1418)

      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)

      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:201)

      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:670)

      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)

      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)

      at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:171)

      at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)

      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)

      at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)

      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

      at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)

      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)

      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

      at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

      at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)

      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

      at io.undertow.server.handlers.MetricsHandler.handleRequest(MetricsHandler.java:64)

      at io.undertow.servlet.core.MetricsChainHandler.handleRequest(MetricsChainHandler.java:59)

      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

      at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

      at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

      at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

      at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

      at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

      at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)

      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)

      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)

      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)

      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)

      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)

      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)

      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)

      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)

      at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)

      at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)

      at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)

      at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)

      at java.lang.Thread.run(Thread.java:748)

      Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection

      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)

      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)

      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)

      at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:109)

      at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)

      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47)

      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)

      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)

      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)

      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1984)

      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1914)

      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1892)

      at org.hibernate.loader.Loader.doQuery(Loader.java:937)

      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)

      at org.hibernate.loader.Loader.doList(Loader.java:2689)

      at org.hibernate.loader.Loader.doList(Loader.java:2672)

      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)

      at org.hibernate.loader.Loader.list(Loader.java:2501)

      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)

      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)

      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:221)

      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)

      at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1538)

      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1506)

      ... 125 more

      Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000460: Error checking for a transaction

      at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:146)

      at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:64)

      at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)

      at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)

      at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)

      ... 145 more

      Caused by: javax.resource.ResourceException: IJ000460: Error checking for a transaction

      at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:425)

      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:789)

      at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138)

      ... 149 more

      Caused by: javax.resource.ResourceException: IJ000459: Transaction is not active: tx=Local transaction (delegate=TransactionImple < ac, BasicAction: 0:ffffac110112:362163b8:5b607141:11 status: ActionStatus.ABORT_ONLY >, owner=Local transaction context for provider JBoss JTA transaction provider)

      at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:409)

      More information can be provided on request.

      Thank you all.

       

        • 1. Re: WildFly 12 & 13 - First transaction access is not active
          smarlow

          You can enable TRACE logging to get more information, as to whether there is an active JTA transaction or not.  From the error, perhaps the JTA transaction was suspended for some reason.  You could also

           

          http://docs.wildfly.org/13/Developer_Guide.html#troubleshooting describes how to get TRACE logging enabled for the JPA container (org.jboss.as.jpa), as well as the JTA transaction manager (com.arjuna).  After enable logging, look in the wildfly standalone/log/server.log file for output (search for the last occurrence of"IJ000460: Error checking for a transaction" message and then read the TRACE logging output, previous to the error).

           

          You should see something in the server.log, logged as org.jboss.as.jpa, about the EntityManager being obtained either under a JTA transaction, or with no JTA transaction.  From the call stack, I suspect there is no active JTA transaction but one seems to be expected.  You should also see something (logged as com.arjuna) in the server.log about the start/end/suspend/resume of each JTA transaction.  If needed, you can add System.out.println("") calls in your code, which should also appear in the server.log, so you can tell which part of your code might be enabling/disabling the JTA transaction.

           

          Scott

          1 of 1 people found this helpful
          • 2. Re: WildFly 12 & 13 - First transaction access is not active
            brunosilva.codiub

            Thanks for the answer.

             

            I've finally found a solution, which was to create a CDI production method of spring data repositories.

             

            @Dependent

            public class FactoryRepository {

             

                @Inject @Database

                private EntityManager entityManager;

             

                @Produces @Repository

                public VwrhSadiLoginRepository getVwrhSadiLoginRepository() {

                     JpaRepositoryFactory jpaRepositoryFactory = new JpaRepositoryFactory(entityManager);

                     return jpaRepositoryFactory.getRepository(VwrhSadiLoginRepository.class);

                }

             

            }

             

            On the service layer:

             

            @RequestScoped

            public class VwrhSadiLoginService {

             

                 @Inject @Database

                 EntityManager entityManager;

             

                 @Inject @Repository

                 VwrhSadiLoginRepository vwrhSadiLoginRepository;

             

                 @Transactional(rollbackOn = Exception.class)

                 public boolean auth(VwrhSadiLoginDto vwrhSadiLoginDto) throws Exception {

                      boolean authentication = false;

             

                      Optional<VwrhSadiLogin> vwrhSadiLogin = vwrhSadiLoginRepository

                           .findByIdEmpresaAndIdMatriculaAndCpfAndSenha(vwrhSadiLoginDto.getIdEmpresa(),

                                               vwrhSadiLoginDto.getIdMatricula(),

                                               vwrhSadiLoginDto.getCpf(),

                                               vwrhSadiLoginDto.getSenha());

             

                      if (vwrhSadiLogin.isPresent()) {

             

                           vwrhSadiLoginDto = Mapper.map(vwrhSadiLogin.get(), VwrhSadiLoginDto.class);

                           vwrhSadiLoginDto.setSenha(null);

             

                           authentication = true;

                      }

             

                      return authentication;

                 }

            }