cancel
Showing results for 
Search instead for 
Did you mean: 

H2 specific errors while connecting to Postgres DB

mohit
Champ on-the-rise
Champ on-the-rise
I am trying to configure activiti to use postgres DB.

My db.properties file is:
db=postgres
jdbc.driver=org.postgresql.Driver
jdbc.url=jdbcSmiley Tongueostgresql://localhost:5432/activiti
jdbc.username=activiti
jdbc.password=activiti

=======================================

My activiti.cfg.xml is something like :

    property name="jdbcUrl" value="jdbcSmiley Tongueostgresql://localhost:5432/activiti"
    property name="jdbcDriver" value="org.postgresql.Driver"
    property name="jdbcUsername" value="activiti"
    property name="jdbcPassword" value="activiti"
    property name="databaseSchemaUpdate" value="true"

=======================================

The test case I am trying to run is:

public class BookOrderTest {
   
   @Test
   public void startBookOrder() {
     ProcessEngine processEngine = ProcessEngineConfiguration
          .createStandaloneProcessEngineConfiguration()
          .buildProcessEngine();
      
      RepositoryService repositoryService = processEngine.getRepositoryService();
      RuntimeService runtimeService = processEngine.getRuntimeService();
      IdentityService identityService = processEngine.getIdentityService();
      TaskService taskService = processEngine.getTaskService();
      repositoryService.createDeployment()
         .addClasspathResource("bookorder.bpmn20.xml")
         .deploy();
      
      // remove tasks already present
      List<Task> availableTaskList = taskService.createTaskQuery().taskName("Work on order").list();
      for (Task task : availableTaskList) {
       taskService.complete(task.getId());
    }   
      
      Map<String, Object> variableMap = new HashMap<String, Object>();
      variableMap.put("isbn", "123456");
      identityService.setAuthenticatedUserId("kermit");
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
            "bookorder", variableMap);
      assertNotNull(processInstance.getId());
      List<Task> taskList = taskService.createTaskQuery().taskName("Work on order").list();
      assertEquals(1, taskList.size());
      System.out.println("found task " + taskList.get(0).getName());
   }
}

=======================================

Now, when I start tomcat, I see my activiti database (the one I created in postgres, gets populated with 25 tables), but when I run the test case shown above I get the below error:
——————————————————

Feb 23, 2016 9:09:46 AM org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl initDatabaseType
SEVERE: Exception while initializing Database connection
org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.ConnectException: Connection refused: localhost" [90067-191]
   at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
   at org.h2.message.DbException.get(DbException.java:168)
   at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:452)
   at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:329)
   at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
   at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
   at org.h2.Driver.connect(Driver.java:72)
   at java.sql.DriverManager.getConnection(DriverManager.java:664)
   at java.sql.DriverManager.getConnection(DriverManager.java:208)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:385)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:835)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:786)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:602)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:590)
   at BookOrderTest.startBookOrder(BookOrderTest.java:25)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:497)
   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)
Caused by: java.net.ConnectException: Connection refused
   at java.net.PlainSocketImpl.socketConnect(Native Method)
   at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
   at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
   at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
   at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
   at java.net.Socket.connect(Socket.java:589)
   at org.h2.util.NetUtils.createSocket(NetUtils.java:122)
   at org.h2.util.NetUtils.createSocket(NetUtils.java:102)
   at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:114)
   at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:448)
   … 39 more

=======================================

I don't understand why I am getting this error and it sure looks like one related to H2 database.

Any pointers?
6 REPLIES 6

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

your configuration still uses H2 DB. Check config files for H2 configuration and change it to postgres.

Regards
Martin

mohit
Champ on-the-rise
Champ on-the-rise
I am sorry, I don't  understand.
Is there any other file except db.properties and activiti.cfg.xml?
As shown in my original question above, I have already updated these files for Postgres.

Also, I would like to point out again from above that:
"when I start tomcat, I see my activiti database (the one I created in postgres, gets populated with 25 tables), but when I run the test case shown above I get the below error:
org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.ConnectException: Connection refused: localhost" [90067-191]
"

mohit
Champ on-the-rise
Champ on-the-rise
Whoa, something odd happened:

I updated my test case to have process-engine bootstrapped like:
ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
       .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
       .setJdbcUrl("jdbcSmiley Tongueostgresql://localhost:5432/activiti")
       .setJdbcUsername("activiti")
       .setJdbcPassword("activiti")
       .buildProcessEngine();

instead of
ProcessEngine processEngine = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration()
.buildProcessEngine();

Can someone please explain what happened and why the values were not picked from activiti.cfg.xml?

Thanks

jbarrez
Star Contributor
Star Contributor
Because now you're instantiating the engine programmatically - no cfg.xml file is involved.

Use the createProcessEngineConfigurationFromResource() method if you want to create a process engine based on an external file.

mohit
Champ on-the-rise
Champ on-the-rise
Hi jbarrez,
Thanks to the reply.

So you are suggesting that if I do:

ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration().buildProcessEngine();

It simply defaults to the default values i.e. H2 db etc.

So, either I instantiate the processEngine programmatically or use createProcessEngineConfigurationFromResource() if I want to read from cfg.xml

Thanks,
Mohit

jbarrez
Star Contributor
Star Contributor
No, after createStandaloneProcessEngineConfiguration you can call many (many) setters, like setJdbcUrl and all ….