Activiti on Play 2 with Spring and Hibernate (JPA) Example


BTW, if you need excellent Java Performance Book, this is the best:

It is the best book I ever read about how to tune Java.

Here is the source code:

Here is the excellent activity book:

Here is an explanation, how we integrate Play with Activiti plus spring and hibernate!

Play! contains JPA and JDBC plugins.

But unfortunately they are not compatible with the way activiti initializes.

But , fortunately, Play allows replacing of plugins by 3-d party JPA and JDBC libs.

At the end, entire stack runs on Spring.

1. we drop Play’s jpa and jdbc support (see what dependencies I have in the /build.sbt instead)

2. We create class Global and instrument it to load the application context with all the goods of Activiti

3. DB connection specified in the application-context.xml

(note, you must install H2 database and start it before you start the app, see that DB connection string matches that of DB)

4. see conf/custom-persistence.xml to understand how I configure persistence

5. in file conf/routes notice 2 activiti relative user actions, which actually required user actions to advance the business process:

# Activiti user actions
POST /computers/saveproposal @controllers.BusinessProcessController.saveProposal()
POST /proposals/:id @controllers.BusinessProcessController.approve(id:Long)

6. see how I defined the BP in the conf/addCompRequest02.bpmn20.xml

Basically it consists of 1 gateway and 2 user tasks plus one service task.

It is a decision. If proposed computer name starts from “Apple”, then request to store it approved automatically.

Otherwise – leave it to manual approval.

7.  Note class BusinessProcessController, it runs all the process logic:

a) it has 2 UI relative actions

b) it has 3 operations, invoked from the business process itself (see comments there)

8.  If you open browser at localhost:9000 you will see a list of computers (initially empty)

9. If you press on “Watch available propositions from clients” you will be traveling to another window.

10. here press the “Add a new computer proposal” button.
In the new window fill the form.
Press “Propose this computer” button.

The comp will be added to the table “Computer_Proposal”

If name of the comp you entered starts from “Apple”, then this comp will be automatically added to table “Computer” and deleted from the table “Computer_Proposa”

This is the rule of the business, described in the exclusive gateway and flows.


If the comp has different name, than “Apple*”, then approval is a User Task (In Activiti way).

For its approval you need press red button “Approve!” in the row of a table of proposed computers.


Then if you return to the / URL, you will have all approved computers appearing in the table.



Looking for cross-platform e-mailing solution for your e-commerce?
Written in scala, open-source, sexy-templates, PHP, Java,.Net site friendly?
Here is the one you can easily and for free integrate in your domain:



About serverbaby

Java programmer.
This entry was posted in activiti, hibernate, play framework, spring and tagged . Bookmark the permalink.

2 Responses to Activiti on Play 2 with Spring and Hibernate (JPA) Example

  1. Pingback: Business Process Modeling Framework , test and developer feedback | Server tips

  2. Pingback: Hibernate and Play 2 on Spring | Server tips

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s