3 Replies Latest reply on Jun 30, 2011 10:33 PM by RuiHua Tang

    How to new a StatefulKnowledgeSession  instance in Spring Web Application

    RuiHua Tang Newbie

      I have used JBPM5 in Spring Web Application

       

      First, I use the following method to create:

       

             StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();

       

      It can be  created successfully.

       

      But, I found that process data and session have not saved to the database

       

      When I use the following methods:

       

      EntityManagerFactory emf = (EntityManagerFactory)Constants.ctx.getBean("entityManagerFactory");

      Environment env = KnowledgeBaseFactory.newEnvironment();

           env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

           env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());

      StatefulKnowledgeSession session = JPAKnowledgeService                                                                                    .newStatefulKnowledgeSession(kbase, null, env);

       

      It gave me the following error messages:

       

      (null: 33, 58): cvc-id.2: There are multiple occurrences of ID value '_4_ContentInput'.

      (null: 33, 58): cvc-attribute.3: The value '_4_ContentInput' of attribute 'id' on element 'dataInput' is not valid with respect to its type, 'ID'.

      (null: 306, 15): cvc-id.1: There is no ID/IDREF binding for IDREF '_3_modelNumber'.

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

                at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:130)

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

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

                at util.JbpmAPIUtil.createKnowledgeSession(JbpmAPIUtil.java:332)

                at util.JbpmAPIUtil.createKnowledgeSession(JbpmAPIUtil.java:347)

                at action.ProcessTaskAPITest.onTest(ProcessTaskAPITest.java:28)

                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:585)

                at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:87)

                at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)

                at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)

                at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:306)

                at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:329)

                at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3048)

                at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)

                at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)

                at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1612)

                at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1396)

                at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1109)

                at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:569)

                at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:463)

                at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:471)

                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.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)

                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:298)

                at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)

                at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)

                at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)

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

      Caused by: java.lang.reflect.InvocationTargetException

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

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

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

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

                at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:116)

                ... 41 more

      Caused by: java.lang.RuntimeException: Could not commit session or rollback

                at org.drools.persistence.SingleSessionCommandService.rollbackTransaction(SingleSessionCommandService.java:317)

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

                ... 46 more

      Caused by: java.lang.RuntimeException: Unable to rollback transaction

                at org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:189)

                at org.drools.persistence.SingleSessionCommandService.rollbackTransaction(SingleSessionCommandService.java:314)

                ... 47 more

      Caused by: java.lang.NullPointerException

                at org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:185)

                ... 48 more

       

       

      Is there anyone who can give some advice for me?

       

      thanks.

        • 2. Re: How to new a StatefulKnowledgeSession  instance in Spring Web Application
          Kris Verlaenen Master

          Could you try setting the Spring JTA transaction manager directly as well?

          env.set( EnvironmentName.TRANSACTION_MANAGER, txManager );

           

          Kris

          • 3. Re: How to new a StatefulKnowledgeSession  instance in Spring Web Application
            RuiHua Tang Newbie

            When i set the Spring JTA transaction manager,it  reported that it cann't find org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager,and i integrated the drools-spring-5.2.0.Final.jar.

             

            It gave me the following error messages

             

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

                      at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:130)

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

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

                      at util.JbpmAPIUtil.createKnowledgeSession(JbpmAPIUtil.java:319)

                      at util.JbpmAPIUtil.createKnowledgeSession(JbpmAPIUtil.java:340)

                      at action.ProcessTaskAPITest.onTest1(ProcessTaskAPITest.java:34)

                      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:585)

                      at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:87)

                      at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)

                      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)

                      at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:306)

                      at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:329)

                      at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3048)

                      at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)

                      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)

                      at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1612)

                      at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1396)

                      at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1109)

                      at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:569)

                      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:463)

                      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:471)

                      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.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)

                      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:298)

                      at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)

                      at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)

                      at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)

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

            Caused by: java.lang.reflect.InvocationTargetException

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

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

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

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

                      at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:116)

                      ... 41 more

            Caused by: java.lang.ClassCastException: [Ljava.lang.Object;

                      at org.drools.marshalling.impl.OutputMarshaller.writePropagationContexts(OutputMarshaller.java:716)

                      at org.drools.marshalling.impl.OutputMarshaller.writeFactHandles(OutputMarshaller.java:280)

                      at org.drools.marshalling.impl.OutputMarshaller.writeSession(OutputMarshaller.java:107)

                      at org.drools.marshalling.impl.DefaultMarshaller.marshall(DefaultMarshaller.java:136)

                      at org.drools.persistence.SessionMarshallingHelper.getSnapshot(SessionMarshallingHelper.java:72)

                      at org.drools.persistence.info.SessionInfo.update(SessionInfo.java:81)

                      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:585)

                      at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:23)

                      at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:80)

                      at org.hibernate.ejb.event.EntityCallbackHandler.preCreate(EntityCallbackHandler.java:49)

                      at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:48)

                      at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)

                      at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)

                      at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)

                      at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)

                      at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)

                      at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)

                      at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)

                      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:585)

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

                      at $Proxy28.persist(Unknown Source)

                      at org.drools.persistence.jpa.JpaPersistenceContext.persist(JpaPersistenceContext.java:17)

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

                      ... 46 more

            java.lang.NullPointerException

                      at org.drools.audit.WorkingMemoryLogger.<init>(WorkingMemoryLogger.java:159)

                      at org.drools.audit.WorkingMemoryFileLogger.<init>(WorkingMemoryFileLogger.java:67)

                      at org.drools.audit.ThreadedWorkingMemoryFileLogger.<init>(ThreadedWorkingMemoryFileLogger.java:34)

                      at org.drools.audit.KnowledgeRuntimeLoggerProviderImpl.newThreadedFileLogger(KnowledgeRuntimeLoggerProviderImpl.java:39)

                      at org.drools.logger.KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(KnowledgeRuntimeLoggerFactory.java:68)

                      at action.ProcessTaskAPITest.onTest1(ProcessTaskAPITest.java:37)

                      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:585)

                      at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:87)

                      at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)

                      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)

                      at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:306)

                      at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:329)

                      at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3048)

                      at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)

                      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)

                      at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1612)

                      at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1396)

                      at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1109)

                      at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:569)

                      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:463)

                      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:471)

                      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.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)

                      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:298)

                      at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)

                      at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)

                      at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)

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

             

            this is my configuration content:

            applicationContext.jpg

            persistence.jpgcreateKSession.jpg

            Thank your answer, my English is not good, I'm sorry to keep you difficult to understand