[jBPM] - Drools / jBPM with EJB3 persistence and transactions
by M Arnold
M Arnold [https://community.jboss.org/people/marnold] created the discussion
"Drools / jBPM with EJB3 persistence and transactions"
To view the discussion, visit: https://community.jboss.org/message/647812#647812
--------------------------------------------------------------
Hi,
I'm trying to use Drools and jBPM using EJB 3.0 and container managed transactions on JBoss AS 5.1. My goal is to ensure that all jBPM work is performed in the container managed transaction.
I've read the …
[View More]applicable documentation http://docs.jboss.org/jbpm/v5.2/userguide/ch07.html here, but I'm still unsure about how to achieve this.
In my SLSB I have:
@PersistenceUnit(unitName = "org.jbpm.persistence.jpa")
protected EntityManagerFactory emf;
@PersistenceContext
protected EntityManager em;
@Resource(mappedName = "java:/TransactionManager")
protected TransactionManager tm;
Then in a @PostConstruct I have:
env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, em);
env.set(EnvironmentName.TRANSACTION_MANAGER, tm);
But when I try:
ksession = JPAKnowledgeService.newStatefulKnowledgeSession(getKnowledgeBase(), null, env);
I get the exception:
Caused by: java.lang.ClassCastException: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate cannot be cast to org.drools.persistence.TransactionManager
at org.drools.persistence.SingleSessionCommandService.initTransactionManager(SingleSessionCommandService.java:265)
at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:115)
... 54 more
I checked the code, and I have to say I agree. ;-) I don't get it. I am expected to create my own class which wraps a real javax.transaction.TransactionManager and implements org.drools.persistence.TransactionManager? What is the correct way to do this?
Thanks in advance for any help, and my apologies if I missed something obvious...
in a stateless session bena
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/647812#647812]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
[View Less]
13 years
[jBPM] - Persist Entity from within ScriptTask - best practice?
by William Timpany
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.…
[View More] 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&con...]
[View Less]
13 years