[jboss-user] [jBPM] - Persist Entity from within ScriptTask - best practice?

William Timpany do-not-reply at jboss.com
Fri Jan 20 07:35:28 EST 2012

William Timpany [https://community.jboss.org/people/wtimpany] created the discussion

"Persist Entity from within ScriptTask - best practice?"

To view the discussion, visit: https://community.jboss.org/message/647820#647820

My question: Is what I am doing sensible/recommended, as I have just started using JBPM.

I have a few Entities stored in my Oracle Database that I want to insert/update/delete as part of my workflow processing.    All the changes need to be processed in the same transaction as the rest of the workflow persistance to ensure the integrity of the flow/data.   I want to keep it all the code as simple as possible.

I am able to do this by using Java within the standard ScriptTask, using the EntityManager extracted from within the kcontext.

The Enities to be updated have been added to the "org.jbpm.persistence.jpa" persistance unit.

Here is the code from within the ScriptTask.   This all works and a new "ScriptActionTriggerBean" is created and persisted to the Oracle DB every time the ScriptTask is called.

-- WorkFlow Code Snipit --
 <tns:import name="com.db.gto.tms.agr.bean.model.workflow.ScriptActionTriggerBean" />
 <tns:import name="javax.persistence.EntityManager" />
 <tns:import name="org.drools.runtime.Environment" />
 <tns:import name="org.drools.runtime.EnvironmentName" />

<scriptTask id="_6" name="PreProcess" scriptFormat="http://www.java.com/java" >
  ScriptActionTriggerBean satb = new ScriptActionTriggerBean();
  satb.setComments("Starting: Script Pre-Processing");
  Environment   env = kcontext.getKnowledgeRuntime().getEnvironment();
  EntityManager em = (EntityManager) env.get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);

Reply to this message by going to Community

Start a new discussion in jBPM at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120120/cfcbecba/attachment.html 

More information about the jboss-user mailing list