2 Replies Latest reply: Apr 30, 2012 2:58 AM by pushpak1981 RSS

jBPM5 Database Exception

pushpak1981 Novice

Hi,

 

I am trying to start multiple processes in parallel using multiple threads (JBoss7.1 CR1 and Oracle Database) I am facing the following error:

 

20:48:37,321 INFO  [stdout] (Thread-103) Thread StartedThread-103
20:48:37,325 INFO  [stdout] (Thread-104) Thread StartedThread-104

20:48:37,328 INFO  [stdout] (Thread-103) Hibernate: select hibernate_sequence.nextval from dual
20:48:37,331 INFO  [stdout] (Thread-104) Hibernate: select hibernate_sequence.nextval from dual
20:48:37,334 INFO  [stdout] (Thread-103) Hibernate: select hibernate_sequence.nextval from dual
20:48:37,335 WARN  [org.hibernate.util.JDBCExceptionReporter] (Thread-104) SQL Error: 0, SQLState: null
20:48:37,342 ERROR [org.hibernate.util.JDBCExceptionReporter] (Thread-104) Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@900b93
20:48:37,339 INFO  [stdout] (Thread-103) Hibernate: select hibernate_sequence.nextval from dual
20:48:37,346 ERROR [org.drools.persistence.SingleSessionCommandService] (Thread-104) Could not commit session: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not get next sequence value
        at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) [hibernate-entitymanager-3.4.0.GA.jar:]
        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226) [hibernate-entitymanager-3.4.0.GA.jar:]
        at org.jbpm.persistence.JpaProcessPersistenceContext.persist(JpaProcessPersistenceContext.java:22) [jbpm-persistence-jpa-5.2.0.Final.jar:]
        at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:43) [jbpm-persistence-jpa-5.2.0.Final.jar:]
        at org.jbpm.process.instance.AbstractProcessInstanceFactory.createProcessInstance(AbstractProcessInstanceFactory.java:36) [jbpm-flow-5.2.0.Final.jar:]
        at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:182) [jbpm-flow-5.2.0.Final.jar:]
        at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:154) [jbpm-flow-5.2.0.Final.jar:]
        at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:135) [jbpm-flow-5.2.0.Final.jar:]
        at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1079) [drools-core-5.3.1.Final.jar:]
        at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:306) [drools-core-5.3.1.Final.jar:]
        at org.drools.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:119) [drools-core-5.3.1.Final.jar:]
        at org.drools.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:38) [drools-core-5.3.1.Final.jar:]
        at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36) [drools-core-5.3.1.Final.jar:]
        at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:345) [drools-persistence-jpa-5.3.1.Final.jar:]
        at org.drools.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:42) [drools-core-5.3.1.Final.jar:]
        at com.l1id.UnitTest.AsynchronousInterceptor.access$0(AsynchronousInterceptor.java:1) [classes:]
        at com.l1id.UnitTest.AsynchronousInterceptor$1.run(AsynchronousInterceptor.java:15) [classes:]
        at java.lang.Thread.run(Thread.java:619) [:1.6.0_03]
Caused by: org.hibernate.exception.GenericJDBCException: could not get next sequence value
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:119) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49) [hibernate-entitymanager-3.4.0.GA.jar:]
        at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:646) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220) [hibernate-entitymanager-3.4.0.GA.jar:]
        ... 16 more
Caused by: java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@900b93
        at org.jboss.jca.adapters.jdbc.WrappedConnection.lock(WrappedConnection.java:151)
        at org.jboss.jca.adapters.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:391)
        at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145) [hibernate-core-3.3.2.GA.jar:]
        at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96) [hibernate-core-3.3.2.GA.jar:]
        ... 25 more

20:48:37,352 INFO  [stdout] (Thread-103) Hibernate: select hibernate_sequence.nextval from dual
20:48:37,449 ERROR [stderr] (Thread-104) Exception in thread "Thread-104" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not get next sequence value

 

From the logs we observed that only one process is completed and other thread goes into an error state. I am using CommandBasedStatefulKnowledgeSession.

 

Has any one faced similar issue.

 

Thanks

  • 1. Re: jBPM5 Database Exception
    Maciej Swiderski Master

    Could you provide bit more details about your setup, such as: do you use single session or session per each thread?

  • 2. Re: jBPM5 Database Exception
    pushpak1981 Novice

    Hi Maciej,

     

    We are using multiple CommandBasedStatefulSession with Asynchronous Interceptor to execute the processes. Please find below the sample code:

     

    @org.junit.Test

        public void testProcessFlow2() throws Exception

        {

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

     

            Environment env = KnowledgeBaseFactory.newEnvironment();

     

            env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

     

              InitialContext ctx = new InitialContext();

     

            KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();   

            builder.add(ResourceFactory.newClassPathResource("HumanTaskTest.bpmn"), ResourceType.BPMN2);       

            builder.add(ResourceFactory.newClassPathResource("UnitTest1.bpmn"), ResourceType.BPMN2);

     

            KnowledgeBase kbase = builder.newKnowledgeBase();

     

            CommandBasedStatefulKnowledgeSession ksession1 = (CommandBasedStatefulKnowledgeSession)JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );

            CommandBasedStatefulKnowledgeSession ksession2 = (CommandBasedStatefulKnowledgeSession)JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );

     

            JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession1);

            JPAWorkingMemoryDbLogger logger2 = new JPAWorkingMemoryDbLogger(ksession2);

     

            CommandBasedWSHumanTaskHandler task = new CommandBasedWSHumanTaskHandler(ksession1);

            CommandBasedWSHumanTaskHandler task1 = new CommandBasedWSHumanTaskHandler(ksession2);

     

            ksession1.getWorkItemManager().registerWorkItemHandler("Human Task", task);

            ksession2.getWorkItemManager().registerWorkItemHandler("Human Task", task1);

     

            AsynchronousInterceptor it1 = new AsynchronousInterceptor();

            AsynchronousInterceptor it2 = new AsynchronousInterceptor();

     

     

            StartProcessCommand start = new StartProcessCommand("com.test.humanTask");

            StartProcessCommand start1 = new StartProcessCommand("com.test.UnitTest1");

     

            Map<String,Object> map = new HashMap<String, Object>();       

            map.put("i", new Integer(53));

     

            start1.setParameters(map);

     

            ksession1.addInterceptor(it1);

            ksession2.addInterceptor(it2);

     

            ksession1.execute(start1);       

            ksession2.execute(start1);

     

            Thread.currentThread().sleep(20000);

        }

     

    Thanks.