AnsweredAssumed Answered

Why could Activiti Test class not getting mysql database access

Question asked by pratikbhatt on Jul 5, 2013
Latest reply on Aug 6, 2014 by frederikheremans1
package org.pratik;

import java.util.List;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.task.Task;

public class ProcessTestFormService {

   public static void main(String[] args) {

      // Create Activiti process engine
      ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration()
            .buildProcessEngine();

      // Get Activiti services
      RepositoryService repositoryService = processEngine
            .getRepositoryService();
      RuntimeService runtimeService = processEngine.getRuntimeService();

      // Deploy the process definition
      repositoryService.createDeployment()
            .addClasspathResource("FinancialReportProcess.bpmn20.xml")
            .deploy();

      // Start a process instance
      String procId = runtimeService.startProcessInstanceByKey(
            "financialReport").getId();

      // Get the first task
      TaskService taskService = processEngine.getTaskService();
      List<Task> tasks = taskService.createTaskQuery()
            .taskCandidateGroup("accountancy").list();
      for (Task task : tasks) {
         System.out
               .println("Following task is available for accountancy group: "
                     + task.getName());

         // claim it
         taskService.claim(task.getId(), "fozzie");
      }

      // Verify Fozzie can now retrieve the task
      tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
      for (Task task : tasks) {
         System.out.println("Task for fozzie: " + task.getName());

         // Complete the task
         taskService.complete(task.getId());
      }

      System.out.println("Number of tasks for fozzie: "
            + taskService.createTaskQuery().taskAssignee("fozzie").count());

      // Retrieve and claim the second task
      tasks = taskService.createTaskQuery().taskCandidateGroup("management")
            .list();
      for (Task task : tasks) {
         System.out
               .println("Following task is available for accountancy group: "
                     + task.getName());
         taskService.claim(task.getId(), "kermit");
      }

      // Completing the second task ends the process
      for (Task task : tasks) {
         taskService.complete(task.getId());
      }

      // verify that the process is actually finished
      HistoryService historyService = processEngine.getHistoryService();
      HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery().processInstanceId(procId)
            .singleResult();
      System.out.println("Process instance end time: "
            + historicProcessInstance.getEndTime());
   }

}

<strong>I am getting this exception when I am accessing class above</strong>

java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:196)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:180)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:176)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:80)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:371)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:80)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:525)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:487)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:332)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:310)
   at org.pratik.ProcessTestFormService.main(ProcessTestFormService.java:20)
Jul 05, 2013 4:29:28 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectDbSchemaVersion
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:54)
   at org.activiti.engine.impl.db.DbSqlSession.getDbVersion(DbSqlSession.java:740)
   at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:696)
   at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1097)
   at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
   at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:75)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:311)
   at org.pratik.ProcessTestFormService.main(ProcessTestFormService.java:20)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at java.sql.DriverManager.getConnection(DriverManager.java:604)
   at java.sql.DriverManager.getConnection(DriverManager.java:190)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:181)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:176)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:80)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:371)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:80)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:131)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:58)
   at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)
   at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69)
   at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
   at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
   at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)
   at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
   at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
   … 13 more

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectDbSchemaVersion
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:54)
   at org.activiti.engine.impl.db.DbSqlSession.getDbVersion(DbSqlSession.java:740)
   at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:696)
   at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1097)
   at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
   at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:75)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:311)
   at org.pratik.ProcessTestFormService.main(ProcessTestFormService.java:20)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at java.sql.DriverManager.getConnection(DriverManager.java:604)
   at java.sql.DriverManager.getConnection(DriverManager.java:190)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:181)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:176)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:80)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:371)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:80)

Outcomes