cancel
Showing results for 
Search instead for 
Did you mean: 

Logging of service tasks in DB issue

abhilashs
Champ in-the-making
Champ in-the-making
I have number of service tasks which executes in a sequential order. In normal scenario when there are no exceptions in any of the service tasks, on completing all the tasks I can see the steps logged in the database with Process Instance ID, Start Time, End Time etc for each Service Tasks.
But when there is an Exception for whatever reason in any of the Service Task. There are no entries in the Database for any of the Service Task which as already completed before the Exception occurred. There is no trace of Process start, completed tasks or failed task.
My requirement is to show at which step the Process as stopped executing a service task due to Errors.
I have integrated Spring with Activiti and using PostgresSQl DB. Is this something to do with Transaction Manager?
Below are my Spring configuration files.

beans.xml:

<blockcode><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

   <import
      resource="classpath:spring-config/spring-hibernate-integeration-beans.xml" />
   <import resource="classpath:spring-config/activiti-config-beans.xml" />
</beans></blockcode>

activiti-config-beans.xml:

<blockcode>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd           
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
                        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="false" />
   </bean>

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

   <bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" />
   <bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" />
   <bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" />
</beans>
</blockcode>

spring-integeration-beans.xml:

<blockcode>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx" xmlns:batch="http://www.springframework.org/schema/batch"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:util="http://www.springframework.org/schema/util"

   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

   <bean
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location">
         <value>/db-config/database-config.properties</value>
      </property>
   </bean>

   <bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="${jdbc.driverClassName}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
   </bean>

   <bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
   </bean>
   <tx:annotation-driven transaction-manager="transactionManager" />

</beans>
</blockcode>
3 REPLIES 3

vasile_dirla
Star Contributor
Star Contributor
Hi,

As I remember, all these subsequent service tasks will be handled in a single transaction for performance reasons that's why you don't see in the DB the progress.
if you want to demarcate the transactions even more granular then you have to use async flag for your tasks.
Probably you need a new transaction for every service in the flow and catch all exception.


hari
Star Contributor
Star Contributor
Abhilash,

Instead of handling the exception, throw it to the function which is calling it. In this way, you get the exception out and you will have its details. I did the same and now I know where exactly the exception has occurred.

Regards,
Hari

hari
Star Contributor
Star Contributor
I mean if you are using a wrapper in between Activiti and your application, throwing the exception from the wrapper makes more sense. If there is no wrapper, when you get the exception, you can always log it to know where it has occurred.

-Hari.