AnsweredAssumed Answered

How to commit DB changes before a call activity?

Question asked by andregs on Sep 8, 2011
Latest reply on Sep 9, 2011 by andregs
Hi,

Suppose I have a process like this:

[attachment=1]ss1.png[/attachment]

I have a method in a stateless session bean to start the process, like this:

@TransactionAttribute(REQUIRED)
public void startProcess(JpaEntity entity) {
   entityManager.persist(entity);

   Map<String, Object> variables = new HashMap<String, Object>();
   variables.put("myEntity", entity);
  
   entityManager.flush();
  
   getRuntimeService().startProcessInstanceById(definition.getId(), variables);
}

I’m trying to pass the “myEntity” var from the parent process to the call activity. However, since I don’t have a “wait state” before the call activity, the method above does not work, throwing an exception like this:

BOM: select nextval(SEQ_GEN_SEQUENCE)
BOM: INSERT INTO (…)
   bind => [8 parameters bound]
BOM: SELECT FIELDS FROM TABLE WHERE (ID = ?)
   bind => [1 parameter bound]
GRAVE: Error while closing command context
org.activiti.engine.ActivitiException: Entity does not exist: br.com.allegrobg.process.MyEntity - 1
   at org.activiti.engine.impl.variable.JPAEntityMappings.findEntity(JPAEntityMappings.java:130)
   at org.activiti.engine.impl.variable.JPAEntityMappings.getJPAEntity(JPAEntityMappings.java:119)
   at org.activiti.engine.impl.variable.JPAEntityVariableType.getValue(JPAEntityVariableType.java:77)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.getValue(VariableInstanceEntity.java:158)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:93)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:97)
   at org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior.execute(CallActivityBehavior.java:67)

If I add a “blank” user task before the call activity (a user task without a form), the commit happens before the call activity, and then everything works:

[attachment=0]ss2.png[/attachment]

This is the question: how can I avoid that blank user task? I mean, how can I commit the JPA Entity in database before the execution enters in the call activity?

This is my activiti.cfg.xml:

<!– glassfish transaction manager –>
<bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:appserver/TransactionManager"></property>
<property name="resourceRef" value="true" />
</bean>

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration">
<property name="dataSourceJndiName" value="jdbc/process" />
<property name="jpaPersistenceUnitName" value="process-pu" />
<property name="jpaHandleTransaction" value="false" /> <!– it's JTA –>
<property name="jpaCloseEntityManager" value="false" /> <!– it's container-managed –>
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />

(…)

Could you please help me here? PS.: I need container-managed transactions.

Thanks in advance,

Outcomes