3 Replies Latest reply on Dec 10, 2008 4:37 AM by kukeltje

    AbstractDbTestCase -> deleteProcessDefinition -> hibernate c

    camunda

      Hi all.

      I have some very strange problems when writing Tests for Commands. I extended AbstractDbTestCase. The tests worked standalone in Eclipse, but when running the whole test suite with Maven, other tests failed.

      Okay, problems with test isolation. So lets clean up after my tests. Hence I deleted the ProcessDefinitions afterwards.Now my tests throw Exceptions :-/

      I stripped it down to the following code, which results in a exception what I don't understand completly yet. Anybody an idea?

      public class WhateverTest extends AbstractDbTestCase
      {
       public void testDBProblem() {
       String xml = "<process-definition name='Test'>"
       +" <start-state name='start'>"
       +" <transition to='end' />"
       +" </start-state>"
       +" <end-state name='end' />"
       +"</process-definition>";
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(xml);
       jbpmContext.deployProcessDefinition(processDefinition);
       ProcessInstance processInstance = processDefinition.createProcessInstance();
       Token token = jbpmContext.loadTokenForUpdate(processInstance.getRootToken().getId());
       jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
       }
      }
      


      The Exception is
      org.jbpm.persistence.JbpmPersistenceException: hibernate commit failed
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:223)
       at org.jbpm.svc.Services.close(Services.java:236)
       at org.jbpm.JbpmContext.close(JbpmContext.java:136)
       at org.jbpm.db.AbstractDbTestCase.closeJbpmContext(AbstractDbTestCase.java:193)
       at org.jbpm.db.AbstractDbTestCase.commitAndCloseSession(AbstractDbTestCase.java:116)
       at org.jbpm.db.AbstractDbTestCase.tearDown(AbstractDbTestCase.java:71)
       at junit.framework.TestCase.runBare(TestCase.java:130)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      Caused by: org.hibernate.AssertionFailure: null id in org.jbpm.graph.exe.ProcessInstance entry (don't flush the Session after an exception occurs)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
       at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
       at org.jbpm.persistence.db.DbPersistenceService.commit(DbPersistenceService.java:262)
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:218)
       ... 18 more
      


      The problem is the jbpmContext.loadTokenForUpdate, if I remove the statement, the test works... But that should work because of Hibernate SessionCache, or am I totally wrong here?

      Thanks for any help or hints!
      Cheers
      Bernd


        • 1. Re: AbstractDbTestCase -> deleteProcessDefinition -> hiberna
          camunda

          And at some time in future I will remember that the forum truncate subjects ;-)

          • 2. Re: AbstractDbTestCase -> deleteProcessDefinition -> hiberna
            camunda

            Investigated further:

            1) With jbpm.loadToken instead of jbpm.loadTokenForUpdate it works

            2) Using jbpmContext.newProcessInstanceForUpdate("Test") also causes the exception.

            So my guess is, that the registered autoSave somehow messes in combination with the deletaion.

            So my next try was to start a new transaction before deleting, and I get a green bar again:

             ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(xml);
             jbpmContext.deployProcessDefinition(processDefinition);
            
             ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("Test");
            // ProcessInstance processInstance = processDefinition.createProcessInstance();
             Token token = jbpmContext.loadTokenForUpdate(processInstance.getRootToken().getId());
            
             newTransaction();
            
             jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
            


            • 3. Re: AbstractDbTestCase -> deleteProcessDefinition -> hiberna
              kukeltje

              Yep, experienced that once to and came to the same solutiuon. Not sure anymore but I even think it was somehow related to the DB being used (id's generated by DB or hibernate)