2 Replies Latest reply on Apr 9, 2009 6:19 PM by sri r

    custom task instance problem

    Gregor Grambow Newbie

      hi everyone!

      i have a problem while trying to use custom task instances in jbpm.
      for the first test i just wantet to copy the usual taskInstance and add an addittional property. the table gets created in the database and everything seems to work, but in the end when i try to save the process instance i get an hibernate error. i'm using jbpm 3.1.1 with ms sql server 2003 and jboss ide 1.6.

      i have done what was mentioned in the userguide and in this forum:

      - create a subclass of TaskInstance

      public class CustomTaskInstance extends TaskInstance {
      
       private String customProperty;
      
       public String getCustomProperty() {
       return customProperty;
       }
      
       public void setCustomProperty(String customProperty) {
       this.customProperty = customProperty;
       }
      
      }
      
      


      - create an implementation of org.jbpm.taskmgmt.TaskInstanceFactory

      public class CustomTaskInstanceFactoryImpl implements TaskInstanceFactory {
      
       public TaskInstance createTaskInstance(ExecutionContext executionContext) {
      
       //just a simple mapping to CustomTaskInstance
      
       return new CustomTaskInstance();
       }
      
      }
      
      


      - update the property jbpm.task.instance.factory to specify the name of custom class

      <bean name='jbpm.task.instance.factory' class='com.dumdidum.pc.CustomTaskInstanceFactoryImpl' singleton='true' />
      


      - create a mapping file for the subclass, for mapping the extra properties you want to save

      <?xml version="1.0"?>
      
      <!DOCTYPE hibernate-mapping PUBLIC
       "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      
      <hibernate-mapping default-access="field">
      
       <class name="com.dumdidum.pc.CustomTaskInstance"
       table="JBPM_CUSTOMTASKINSTANCE"
       discriminator-value="C">
       <id name="id" column="ID_"><generator class="native" /></id>
       <discriminator type="char" column="CLASS_"/>
      
       <property name="name" column="NAME_" />
       <property name="description" column="DESCRIPTION_" type="string_max" length="4000"/>
       <property name="actorId" column="ACTORID_" index="IDX_TASK_ACTORID"/>
       <property name="create" column="CREATE_" />
       <property name="start" column="START_" />
       <property name="end" column="END_" />
       <property name="dueDate" column="DUEDATE_" />
       <property name="priority" column="PRIORITY_" />
       <property name="isCancelled" column="ISCANCELLED_" />
       <property name="isSuspended" column="ISSUSPENDED_" />
       <property name="isOpen" column="ISOPEN_" />
       <property name="isSignalling" column="ISSIGNALLING_" />
       <property name="isBlocking" column="ISBLOCKING_" />
       <property name="customProperty" column="CUSTOMPROPERTY_" />
      
       <many-to-one name="task"
       column="TASK_"
       foreign-key="FK_TASKINST_TASK"/>
       <many-to-one name="token"
       column="TOKEN_"
       foreign-key="FK_TASKINST_TOKEN"/>
       <many-to-one name="swimlaneInstance"
       column="SWIMLANINSTANCE_"
       foreign-key="FK_TASKINST_SLINST"/>
       <many-to-one name="taskMgmtInstance"
       column="TASKMGMTINSTANCE_"
       foreign-key="FK_TASKINST_TMINST"/>
      
       <map name="variableInstances" cascade="all">
       <key column="TASKINSTANCE_" foreign-key="FK_VAR_TSKINST"/>
       <index type="string" column="NAME_" />
       <one-to-many class="org.jbpm.context.exe.VariableInstance" />
       </map>
       <set name="pooledActors"
       cascade="all"
       table="JBPM_TASKACTORPOOL">
       <key column="TASKINSTANCE_" foreign-key="FK_TASKACTPL_TSKI"/>
       <many-to-many class="org.jbpm.taskmgmt.exe.PooledActor" column="POOLEDACTOR_" />
       </set>
       <list name="comments" cascade="all" >
       <key column="TASKINSTANCE_" />
       <index column="TASKINSTANCEINDEX_" />
       <one-to-many class="org.jbpm.graph.exe.Comment" />
       </list>
      
       </class>
      
      </hibernate-mapping>
      
      


      - add that mapping file to the list of mapping files

      <mapping resource="com/dumdidum/pc/CustomTaskInstance.hbm.xml"/>
      


      - use custom assignementHandler

      public class MyAssignmentHandler implements AssignmentHandler {
      
       public void assign(Assignable assignable, ExecutionContext executionContext)
       throws Exception {
      
      
       CustomTaskInstance cti = (CustomTaskInstance) assignable;
       cti.setActorId("UserPc1");
       cti.setCustomProperty("testtest");
      
       }
      
      }
      
      


      the simple process:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <process-definition
       xmlns="urn:jbpm.org:jpdl-3.1" name="simpleTask">
       <start-state name="start">
       <transition name="" to="task1"></transition>
       </start-state>
       <end-state name="end1"></end-state>
       <task-node name="task1">
       <task name="testTask">
       <assignment class="com.dumdidum.pc.MyAssignmentHandler"></assignment>
       </task>
       <transition name="" to="state1"></transition>
       </task-node>
       <state name="state1">
       <transition name="" to="end1"></transition>
       </state>
      </process-definition>
      


      the result is the following error when trying to flush the session:

      17:10:42,305 [main] DEBUG Services : executing default save operations
      17:10:42,305 [main] DEBUG HibernateSaveOperation : saving process instance
      17:10:42,305 [main] DEBUG SaveLogsOperation : flushing logs to logging service.
      org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:171)
       at org.jbpm.svc.Services.close(Services.java:211)
       at org.jbpm.JbpmContext.close(JbpmContext.java:141)
       at com.rockwell.pc.JBPMWrapper.participateInProcess(JBPMWrapper.java:218)
       at com.rockwell.pc.ProcessTester.main(ProcessTester.java:36)
      Caused by: org.hibernate.AssertionFailure: null id in org.jbpm.taskmgmt.log.TaskAssignLog entry (don't flush the Session after an exception occurs)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)17:10:42,315 [main] WARN JDBCExceptionReporter : SQL Error: 547, SQLState: 23000
      17:10:42,315 [main] ERROR JDBCExceptionReporter : INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_LOG_TASKINST'. The conflict occurred in database 'JBPM', table 'JBPM_TASKINSTANCE', column 'ID_'.
      17:10:42,315 [main] DEBUG JbpmContext : closing JbpmContext
      17:10:42,315 [main] DEBUG Services : closing service 'persistence': org.jbpm.persistence.db.DbPersistenceService@1abdac9
      17:10:42,315 [main] DEBUG DbPersistenceService : committing hibernate transaction
      17:10:42,325 [main] ERROR AssertionFailure : an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
      org.hibernate.AssertionFailure: null id in org.jbpm.taskmgmt.log.TaskAssignLog entry (don't flush the Session after an exception occurs)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
       at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:161)
       at org.jbpm.svc.Services.close(Services.java:211)
       at org.jbpm.JbpmContext.close(JbpmContext.java:141)
       at com.rockwell.pc.JBPMWrapper.participateInProcess(JBPMWrapper.java:218)
       at com.rockwell.pc.ProcessTester.main(ProcessTester.java:36)
      17:10:42,345 [main] ERROR Services : problem closing service 'persistence'
      org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:171)
       at org.jbpm.svc.Services.close(Services.java:211)
       at org.jbpm.JbpmContext.close(JbpmContext.java:141)
       at com.rockwell.pc.JBPMWrapper.participateInProcess(JBPMWrapper.java:218)
       at com.rockwell.pc.ProcessTester.main(ProcessTester.java:36)
      Caused by: org.hibernate.AssertionFailure: null id in org.jbpm.taskmgmt.log.TaskAssignLog entry (don't flush the Session after an exception occurs)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
       at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:161)
       ... 4 more
      
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
       at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:161)
       ... 4 more
      org.jbpm.JbpmException: problem closing services {persistence=org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session}
       at org.jbpm.svc.Services.close(Services.java:223)
       at org.jbpm.JbpmContext.close(JbpmContext.java:141)
       at com.rockwell.pc.JBPMWrapper.participateInProcess(JBPMWrapper.java:218)
       at com.rockwell.pc.ProcessTester.main(ProcessTester.java:36)
      Caused by: org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:171)
       at org.jbpm.svc.Services.close(Services.java:211)
       ... 3 more
      Caused by: org.hibernate.AssertionFailure: null id in org.jbpm.taskmgmt.log.TaskAssignLog entry (don't flush the Session after an exception occurs)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:48)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
       at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
       at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:161)
       ... 4 more
      17:10:42,345 [main] DEBUG Services : closing service 'logging': org.jbpm.logging.db.DbLoggingService@1e8c585
      
      


      any help would be appreciated!
      best regards
      gregor