3 Replies Latest reply: Jul 13, 2012 6:43 AM by suprit chaudhary RSS

    JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env)

    gigazhang Newbie

      throw exception

       

      javax.persistence.TransactionRequiredException: No local transaction to join

          at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:407)

          at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350)

          at $Proxy32.joinTransaction(Unknown Source)

          at org.drools.persistence.jpa.JpaPersistenceContext.joinTransaction(JpaPersistenceContext.java:29)

          at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:152)

          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

          at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:129)

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:67)

          at org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:122)

          at com.baison.demo.jbpm.commons.JbpmHelper.createSession(JbpmHelper.java:255)

          at com.baison.demo.jbpm.service.TaskProcessServiceImpl.saveProcess(TaskProcessServiceImpl.java:71)

          at com.baison.demo.jbpm.service.TaskProcessServiceImpl.commitProcess(TaskProcessServiceImpl.java:125)

          at com.baison.demo.jbpm.controller.TaskProcessController.getUserCommitProcess(TaskProcessController.java:80)

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

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

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

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

          at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)

          at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)

          at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)

          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)

          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)

          at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)

          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)

          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)

          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)

          at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)

          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

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

      java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:143)

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:67)

          at org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:122)

          at com.baison.demo.jbpm.commons.JbpmHelper.createSession(JbpmHelper.java:255)

          at com.baison.demo.jbpm.service.TaskProcessServiceImpl.saveProcess(TaskProcessServiceImpl.java:71)

          at com.baison.demo.jbpm.service.TaskProcessServiceImpl.commitProcess(TaskProcessServiceImpl.java:125)

          at com.baison.demo.jbpm.controller.TaskProcessController.getUserCommitProcess(TaskProcessController.java:80)

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

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

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

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

          at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)

          at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)

          at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)

          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)

          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)

          at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)

          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)

          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)

          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)

          at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)

          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

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

      Caused by: java.lang.reflect.InvocationTargetException

          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

          at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:129)

          ... 38 more

      Caused by: javax.persistence.TransactionRequiredException: No local transaction to join

          at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:407)

          at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350)

          at $Proxy32.joinTransaction(Unknown Source)

          at org.drools.persistence.jpa.JpaPersistenceContext.joinTransaction(JpaPersistenceContext.java:29)

          at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:152)

          ... 43 more

        • 1. Re: JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env)
          Mauricio Salatino Master

          How did you configure Persistence and Transactions?

          Can you explain a little bit more about your context?

          Cheers

          • 2. Re: JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env)
            gigazhang Newbie

            <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

                    <property name="driverClassName">

                        <value>oracle.jdbc.driver.OracleDriver</value>

                    </property>

                    <property name="url">

                        <value>jdbc:oracle:thin:@//192.168.175.40:1521/ORCL</value>

                    </property>

                    <property name="username">

                        <value>demo</value>

                    </property>

                    <property name="password">

                        <value>demo</value>

                    </property>

                    <property name="initialSize">

                        <value>5</value>

                    </property>

                    <property name="maxActive">

                        <value>80</value>

                    </property>

                    <property name="maxIdle">

                        <value>20</value>

                    </property>

                    <property name="maxWait">

                        <value>3000</value>

                    </property>

                </bean>

             

                <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

                    <property name="dataSource" ref="dataSource" />

                    <property name="persistenceUnitName" value="org.drools.persistence.jpa.local" />

                </bean>

             

                <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">

                    <property name="entityManagerFactory" ref="emf" />

                    <property name="dataSource" ref="dataSource" />

                </bean>

             

                <drools:grid-node id="node" />

             

                <drools:kbase id="kbase" node="node">

                    <drools:resources>

                        <drools:resource type="BPMN2" source="classpath:bpmn/MyProcess.bpmn" />

                    </drools:resources>

                </drools:kbase>

               

                <drools:ksession id="ksession" type="stateful" kbase="kbase" node="node">

                    <drools:configuration>

                        <drools:jpa-persistence>

                            <drools:transaction-manager ref="transactionManager" />

                            <drools:entity-manager-factory ref="emf" />

                        </drools:jpa-persistence>

                    </drools:configuration>

                </drools:ksession>

            • 3. Re: JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env)
              suprit chaudhary Newbie

              You need to start transaction by calling begin() on transactionManager before you call to create session JPAKnowledgeService.newStatefulKnowledgeSession.


              bitronix.tm.BitronixTransactionManager transactionManager= TransactionManagerServices.getTransactionManager();

              transactionManager.begin();

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              kbuilder.add(ResourceFactory.newFileResource("test.bpmn"), ResourceType.BPMN2);

              KnowledgeBase kbase = kbuilder.newKnowledgeBase();

              EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

              Environment env = KnowledgeBaseFactory.newEnvironment();

              env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

              env.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);

              Properties properties = new Properties();

              properties.put("drools.processInstanceManagerFactory","org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");

              properties.put("drools.processSignalManagerFactory","org.jbpm.persistence.processinstance.JPASignalManagerFactory");

              KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);

              StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);