Infinity Process Platform Hibernate Data Type Example

The Infinity Process Platform installation contains a small example on how to use this data type. Click the following link to download this example in a ZIP file:

Unpack the ZIP file to an example location. We refer to this folder as <hibernate-example>. The folder provides a process model as well as source files needed for the project. The example process model, which resides in folder <hibernate-example>/hibernate/dat, covers the following use cases:

You can import this process model into an Eclipse project. The classes used in the examples are located in the hibernate/src folder.

Preconditions

To execute the example it is necessary to set up a Infinity Process Platform Audit Trail. The examples are based on a Derby database.

Per default the standard Infinity audit trail is used. In case you like to use another audit trail or database, you need to adjust the ipp-hibernate-spring-context.xml file located in the WEB-INF/config/ipp/spring folder of your Web application. Adjust the hibernateDataSource Spring bean accordingly and, if you do not use a Derby database, the hibernatePropertiesBean.

Configuration

Prepare the working environment for this example:

Setting up a Configuration without Spring

If you like to use the configuration without Spring, use the hibernate.cfg.xml file provided in the example. In that case you have to adjust one of the following context files depending on the environment your work in:

Adjust the context file to the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright (c) 2011, 2015 SunGard CSA LLC and others.
-->
<!--
   - Application context for a Infinity Process Engine client.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:jee="http://www.springframework.org/schema/jee"
   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
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

   <bean id="hibernateSessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref bean="hibernateDataSource" />
      </property>
      <property name="jtaTransactionManager">
         <bean factory-bean="carnotTxManager" factory-method="getTransactionManager"/>
      </property>
      <property name="configLocation">
       <value>classpath:com/sungard/hibernate/hibernate.cfg.xml</value>
      </property>
   </bean>

   <!-- Use xaAuditTrailConnectionFactory if you want to use the same datasource as the
        Engine. Otherwise configure the hibernateJNDIDataSource if you want to use a
        different datasource and set the name attribute to hibernateJNDIDataSource -->
   <alias name="xaAuditTrailConnectionFactory" alias="hibernateDataSource" />
   
   <jee:jndi-lookup id="hibernateJNDIDataSource" lazy-init="true"
      jndi-name="jdbc/AuditTrail.DataSource" resource-ref="true" />

</beans>

If working in RAD, adjust the hibernate.cfg.xml as follows:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
        <property name="hibernate.connection.autocommit">false</property>
        
           <!-- this will show us all sql statements -->
         <property name="hibernate.show_sql">true</property>
           <!-- this will create the database tables for us -->
         <property name="hibernate.hbm2ddl.auto">update</property>

         <property name="hibernate.cache.use_second_level_cache">false</property>
   
         <mapping resource="com/sungard/hibernate/employee.hbm.xml"/>
               
    </session-factory>
</hibernate-configuration>

Extend the hibernateSessionFactory with the following property:

<property name="configLocation">
   <value>classpath:com/sungard/hibernate/hibernate.cfg.xml</value>
</property>

Modeling the Hibernate Example

For our Hibernate example model we provide the following processes:

Creating Hibernate Data Process

First create a process to create the Hibernate data and fill it with data.

  1. Create a manual trigger.
  2. Create a manual activity Enter Data and add a transition from the manual trigger.
  3. Create an application activity Fill Hibernate Data and add a transition from Enter Data.
  4. Create a subprocess activity EmployeeInCondition and add a transition from Fill Hibernate Data.
  5. Create a plain Java application Init Employee.
  6. Open the property page of the application and enter the following application data:

    TestEmployeeApp Application Properties
    Figure: TestEmployeeApp Application Properties

  7. Create three primitive data and name them empId, firstName and lastName.
  8. Set out-data mappings from the Enter Data activity to these data.
  9. Set in-data mappings from these data to the activity Fill Hibernate Data.
  10. Create a hibernate data Hibernate Data.
  11. In the Hibernate Data property page, select the class com.sungard.hibernate.Employee in the Class Name entry.

    Class Name
    Figure: Select the Class Name

  12. Create an out-data mapping from activity Fill Hibernate Data to the hibernate data.
  13. Choose returnValue : Employee as access point:

    Access Point
    Figure: Access Point for Hibernate Data

  14. To display the Hibernate data, select EmployeeInCondition as subprocess in the EmployeeInCondition activity properties page. Refer to section Display Hibernate Data in a Condition for details on this process.

    Select Subprocess
    Figure: Select Subprocess

The diagram now looks similar as displayed in the following screenshot:

Create Employee
Figure: Create Employee Process Diagram

Displaying Hibernate Data in a Condition

Now we create a process that can be used to display our Hibernate data. The process is using a condition to only display the data in case it contains values.

  1. First create a Start event followed by a Route activity with split behavior OR:

  2. Create an application activity Show Employee
  3. Create an in-data mapping from the hibernate data to activity Show Employee.
  4. In the property page of Show Employee, add three in-data mappings from the Hibernate data with the following Ids and data path:

    Access Point

    Access Point

    Access Point

  5. Add a transition from the gateway of the Route activity to be performed only in case the Hibernate data is set:
    HibernateData != null

    Transition Condition

  6. Create a simple manual activity No Employee
  7. Create a primitive data to be displayed in case no Hibernate data is set.

    Null Object Data

  8. Add an in-data mapping from this data to No Employee
  9. Add a transition from the Route activity gateway to No Employee with condition OTHERWISE, so that it will be performed if no Hibernate Data is set. Use

    No Hibernate Data set Condition

The complete process now looks similar as in the following screenshot:

HibernateInCondition Process
Figure: HibernateInCondition Process

Deleting Hibernate Data Process

Create a process definition to clear hibernate data:

  1. Create a manual trigger followed by a subprocess activity CreateEmployee.
  2. In the property page select the CreateEmployee process definition as subprocess, which we created in section Creating Hibernate Data Process.


    Figure:

  3. Create an application activity Delete Employee.
  4. Set a transition from the CreateEmployee to the application activity.
  5. Add a plain Java application Clear Employee.
  6. Open the property page of the application and enter the following application data:

    Clear Employee Application Properties
    Figure: Clear Employee Application Properties

  7. Connect the application to the Delete Employee application activity.
  8. Drag the hibernate data Hibernate Data, which we created in the Create Employee process definition, from the Outline view to the diagram.
  9. In the property page of the Delete Employee activity, add an out-data mapping to the hibernate data with access point returnValue : Employee.

    Out-Data Mapping to Hibernate Data
    Figure: Out-Data Mapping to Hibernate Data.

  10. To display the Hibernate data, create a subprocess activity EmployeeInCondition to call process EmployeeInCondition, which we created in section Display Hibernate Data in a Condition.

The completed process should look like in the following screenshot:

Delete Employee
Figure: Delete Employee Process Diagram

Updating Hibernate Data Process

At last we create a process which provides the option to update a Hibernate data:

  1. Create a manual trigger followed by an application activity Create Employee, which initiates a Hibernate Data with a random value for the Employee Id.
  2. Drag application Init Employee, which we created in section Creating Hibernate Data Process, from the Outline view to the diagram and connect it to the application activity.
  3. Drag the Hibernate Data from the Outline tree to the diagram.
  4. In the properties page of the application activity, create an application out data mapping to the Hibernate data with access point complete():

    Out Data Mapping

  5. Create a follow-up manual activity Update Employee to provide the option to enter values (last name and first name) for the generated Hibernate Data.
  6. Create the following out data mappings from this activity to our Hibernate Data:
  7. To show our updated Hibernate Data, create a subsequent subprocess activity EmployeeInCondition as in the processes in the sections above.

The completed process now looks similar to the one in the following screenshot:

Update Hibernate Data Process Diagram
Figure: Update Hibernate Data Process Diagram

Running the Example

Now deploy your model and test it, e.g. in the Infinity Process Platform Portal.

Creating Hibernate Data

Start process CreateEmployee and enter the first name, last name and id of the Employee Hibernate Data.

Enter Hibernate Data
Figure: Enter Hibernate Data

After completing the activity, the EmployeeInCondition is activated and displays the resulting Hibernate data with values.

Display Hibernate Data
Figure: Display Hibernate Data

Clearing Hibernate Data

Start process DeleteEmployee. First the subprocess CreateEmployee is activated, where you enter values for the Hibernate data and see this data displayed as described in section Creating Hibernate Data.

Now the application Delete Employee is activated returning a Null value. The condition in subprocess EmployeeInCondition evaluates to OTHERWISE as the HibernateData is null. Thus the No Employee activity is activated, which displays the NullObjInfo data notifying that no data is available.

No Employee activity
Figure: No Employee activity

Note that the actual Hibernate object itself is not deleted, but set to null!

Updating Hibernate Data

Start process UpdateEmployee. The subprocess activity CreateEmployee is activated, which uses the process described in section Creating Hibernate Data Process. As it has no incoming data to fill the Hibernate data, it uses the Access Point Complete() without parameters, which creates a random value for the Employee Id.

The subsequent activity reads data for the Employee first and last name and writes them to the Hibernate data.

Enter Hibernate Data
Figure: Enter Hibernate Data

Now subprocess EmployeeInCondition is activated to display the resulting Hibernate data. The entered last and first name are displayed with a random value for the Employee Id.

Updated Hibernate Data
Figure: Updated Hibernate Data