6 Replies Latest reply on Jan 11, 2006 10:14 AM by Lisa Mark

    How to customize TaskInstance?

    Lisa Mark Newbie

      Hi.,
      I want to customize TaskInstance by extending it. I read the doc and forum discussions about it: I had done like
      - create a subclass of TaskInstance (did)
      - update the property jbpm.task.instance.class to specify the name of custom class (did)

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

      I tried to extend TaskInstance in my custom subclass mapping file, but I'm getting exception "No discriminator found for [subclass]. Discriminator is needed when 'single-table-per-hiearchy' is used and a class has subclasses"


      Any help is greatly appreciated.
      (sample code, if possible)

      Thanks.

        • 1. Re: How to customize TaskInstance?
          Coby Young Newbie

          I struggled with this a while, and couldn't ever get my new mapping file to play nice with the existing (umodified) TaskInstance.hbm.xml mapping file.

          I'm not very familiar with hibernate, but the info at this http://ndpsoftware.com/HibernateMappingCheatSheet.html helped me figure out what needed to be done (see the Subclasses section).

          It seems that when you want to use a 'single-table-per-hierarchy' that you need to add a discrimintor to the superclass mapping file (as well as the subclass mapping file). So, I ended up creating a new hibernate mapping file (MyTaskInstance.hbm.xml) that looks something like this...

          <?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">
          
           <!-- this class mapping is an exact copy of the stock
           TaskInstance.hbm.xml mapping, except a discrimintor
           column (and value) have been added to support
           a subclass that can share the same table -->
           <class name="org.jbpm.taskmgmt.exe.TaskInstance"
           table="JBPM_TASKINSTANCE"
           discriminator-value="T"
           lazy="false">
           <id name="id" column="ID_"><generator class="native" /></id>
          
           <discriminator column="subclass" type="character"/>
          
           <property name="name" column="NAME_" />
           <property name="description" column="DESCRIPTION_" 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="isSignalling" column="ISSIGNALLING_" />
           <property name="isBlocking" column="ISBLOCKING_" />
          
           <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"/>
          
           <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>
          
          
           <!-- This is the new subclass, it has one additional
           field (customKey) that needs to be persisted too -->
           <subclass name="myapp.MyTaskInstance"
           extends="org.jbpm.taskmgmt.exe.TaskInstance"
           discriminator-value="M"
           lazy="false">
           <property name="customKey" column="CUSTOMKEY_" />
           </subclass>
          
           </class>
          
          </hibernate-mapping>
          


          Then, I removed the entry in hibernate.cfg.xml that said...

          <mapping resource="org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml"/>
          


          And replaced it with a line that says...

          <mapping resource="myapp/MyTaskInstance.hbm.xml"/>
          


          I would have prefered to find a way of accomplishing the same results without having to muck with the superclass mapping file, but this seemed to work out ok.

          • 2. Re: How to customize TaskInstance?
            Ronald van Kuijk Master

            it's not sample 'code' you need, it's a config example. This is a hibernate config issue. search the hibernate forums for this, I think you'll find something.

            http://forums.hibernate.org/viewtopic.php?t=939394&view=next&sid=00ce4a4831ab25fb3e0f13afe878d5e0

            • 3. Re: How to customize TaskInstance?
              Administrator Administrator Novice

              the mapping file of the task instance should be updated to this: (next 3.1 releases will include this update)

              <class name="org.jbpm.taskmgmt.exe.TaskInstance"
               table="JBPM_TASKINSTANCE"
               discriminator-value="T">
               <id name="id" column="ID_"><generator class="native" /></id>
               <discriminator type="char" column="CLASS_"/>
              


              now you just have to make sure that you include the discriminator-value attribute in your subclasses with a different value in then 'T'

              i think that should solve it.

              regards, tom.

              • 4. Re: How to customize TaskInstance?
                Fyrose Gajula Newbie

                Hi,

                I also hope the same to change the discriminator-value attribute insteadof 'T' in the mapping file. This could be work then.

                Regards

                • 5. Re: How to customize TaskInstance?
                  Lisa Mark Newbie


                  Thanks for your replies.

                  [B]Happy to know that the next jBPM release comes with discriminator value.

                  • 6. Re: How to customize TaskInstance?
                    Lisa Mark Newbie

                    Thanks for your replies.

                    Happy to know that the next jBPM release comes with discriminator value.

                    Greetz.