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 --
<extensionElements>
 <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" />
</extensionElements>

<scriptTask id="_6" name="PreProcess" scriptFormat="http://www.java.com/java"; >
 <script>
  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);
  em.persist(satb);
 </script>
</scriptTask>
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/647820#647820]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to