AnsweredAssumed Answered

Activiti requires H2 driver when configured with Postgres

Question asked by marcinj on Apr 13, 2011
Latest reply on Apr 13, 2011 by jbarrez
Hi,

I believe there is a mistake in org.activiti.engine.ProcessEngineConfiguration and/or in org.activiti.engine.ProcessEngine.
I have configured my test program to work with Postgres, but I still need to add H2 drivers to my classpath, otherwise I get this exception:

Exception in thread "main" org.apache.ibatis.datasource.DataSourceException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:179)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:57)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:349)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:55)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:426)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:390)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:259)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:236)
   at pac1.Prog2.main(Prog2.java:29)
Caused by: java.lang.ClassNotFoundException: org.h2.Driver
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:173)
   … 8 more

The example code is as follows: (it's based on the 10 minute example):

   ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
      .createStandaloneProcessEngineConfiguration()
      .setDatabaseType("postgres").setJdbcUsername("activiti")
      .setJdbcPassword("activiti")
      .setJdbcUrl("jdbc:postgresql://127.0.0.1:54322/activiti");

   processEngine = processEngineConfiguration.buildProcessEngine();

Adding the following line solves the issue:

.setJdbcDriver("org.postgresql.Driver")

The class name of H2 driver is hardwired in the ProcessEngineConfiguration, probably setting the databaseType to "postgres" should change that.

Thanks,
Marcin Jaskolski

Outcomes