cancel
Showing results for 
Search instead for 
Did you mean: 

Struggling with standalone H2 database

praveenr
Champ in-the-making
Champ in-the-making
I am trying to get the standalone H2 working with Activiti engine, but I keep getting the below error when executing a BPMN example from Eclipse:

SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error opening session.  Cause: org.h2.jdbc.JdbcSQLException: Connection is broken: "session closed" [90067-132]
### The error may exist in org/activiti/db/mapping/entity/EventSubscription.xml
### The error occurred while processing mapper_resultMap[compensateResultMap]
### Cause: org.h2.jdbc.JdbcSQLException: Connection is broken: "session closed" [90067-132]

The Activiti Explorer is working and modified the "db.properties" as:
db=h2
jdbc.driver=org.h2.Driver
#jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
jdbc.url=jdbc:h2:tcp://localhost/~/activiti
jdbc.username=sa
jdbc.password=

Instead of the localhost, I tried IP address too, but the result is same. Any guidance would be greatly appreciated.

Thanks
9 REPLIES 9

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

you use in mem DB -> you should be able to provide jUnit test easily.
https://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin

Hi Martin,
     Thanks for taking the time to respond. My unit tests work properly with in memory H2 DB. No issues on that.
The problem is when I install a standalone H2 database and try to execute the JUnit test with the standalone H2 DB, I get the above exception.
In "db.properties" my jdbc.url value is "jdbc.url=jdbc:h2:tcp://localhost/~/activiti"
FYI, I can login into the H2 console on its own and see the Activiti related schema-table objects from the H2 console.

Appreciate your time on your guidance.

Thanks

martin_grofcik
Confirmed Champ
Confirmed Champ

Hi Martin,
         I am trying to run the exact example code as in the link you have shared. My H2 version is "H2 1.3.176 (2014-04-05)", so no issues on that. But my Activiti Engine version is 5.19.0.2.

-Praveen

shivam_0311
Champ in-the-making
Champ in-the-making
Hi Praveen,
   
Are you using <code>ProcessEngine processEngine = ProcessEngineConfiguration
   .createStandaloneProcessEngineConfiguration()
    .buildProcessEngine();</code>
method to create the process-engine.If yes,then try
<code>ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); </code> method for creating the same and create activiti.cfg.xml with your H2 database configuration and put it in classpath of your project.
Then try to run your program.

praveenr
Champ in-the-making
Champ in-the-making
Thanks for the suggestion. In the examples project (from the book) there is a activiti.cfg.xml file and I have modified the same as:
<code>
    <property name="databaseType" value="h2" />
    <property name="jdbcUrl" value="jdbc:h2:tcp://localhost/~/activiti"/>
    <property name="jdbcDriver" value="org.h2.Driver" />
    <property name="jdbcUsername" value="sa" />
    <property name="jdbcPassword" value="" />
  
    <property name="databaseSchemaUpdate" value="true" />
</code>

With this and the JUnit code change, I get a new exception:
<code>
Feb 23, 2016 11:10:23 AM org.activiti.engine.ProcessEngines initProcessEnginFromResource
INFO: initializing process engine for resource file:/C:/Users/jc347300/workspace/BPMN_Examples/target/classes/activiti.cfg.xml
23 Feb 2016 11:10:24,020 [main]  INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader:315 - Loading XML bean definitions from resource loaded through InputStream
Feb 23, 2016 11:10:24 AM org.activiti.engine.impl.db.DbSqlSession dbSchemaUpgrade
INFO: upgrading activiti engine schema from 5.20.0.1 to 5.9
Feb 23, 2016 11:10:24 AM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
<strong>
java.lang.NumberFormatException: For input string: "20.0.1"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
</strong>
</code>

and the "pom.xml" file section for Activiti version is:
<code>
<properties>
  <activiti-version>5.9</activiti-version>
  <spring-version>3.0.5.RELEASE</spring-version>
  <cxf-version>2.4.4</cxf-version>
  <drools-version>5.3.0.Final</drools-version>
</properties>
</code>

shivam_0311
Champ in-the-making
Champ in-the-making
Is there any failure trace in junit console?

praveenr
Champ in-the-making
Champ in-the-making
The JUnit trace is:
<code>
java.lang.NullPointerException
at org.bpmnwithactiviti.BookOrderTest.startBookOrder(BookOrderTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
</code>

Marking line 32:
<code>
@Test
public void startBookOrder() {
//  ProcessEngine processEngine = ProcessEngineConfiguration
//   .createStandaloneProcessEngineConfiguration()
//    .buildProcessEngine();
 
  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//  System.out.println("Engine Name: " + processEngine.getName());

//Below line is 32
           RepositoryService repositoryService = processEngine.getRepositoryService();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  IdentityService identityService = processEngine.getIdentityService();
</code>

shivam_0311
Champ in-the-making
Champ in-the-making
It is throwing NullPointerException because ProcessEngine is not creating properly(May be some configuration issues).
Just give it a try:
<code>
ProcessEngine processEngine = ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResourceDefault()
    .buildProcessEngine();
</code> in place of above code to create processEngine.
Once again check your activiti.cfg.xml.