cancel
Showing results for 
Search instead for 
Did you mean: 

How to commit DB changes before a call activity?

andregs
Champ in-the-making
Champ in-the-making
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,
4 REPLIES 4

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Wow… Such a long post and if you searched a little you might have found async continuatons and 'ACT-126'. That is what you need

andregs
Champ in-the-making
Champ in-the-making
Thank you! That's really what I need. So I have to wait for the next version of Activiti, right? Meanwhile, I'm trying to do the commit via receive task + timeout, because it's better than my previous blank user task approach. However, this exception is thrown:

BOM: INSERT INTO MYTABLE (FIELDS) VALUES (?)
bind => [8 parameters bound]

GRAVE: Error while closing command context
org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[13328] was updated by another transaction concurrently
at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:425)
at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:338)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:147)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:103)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
at org.activiti.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:59)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.jobexecutor.JobAcquisitionThread.run(JobAcquisitionThread.java:63)

GRAVE: exception during job acquisition: TimerEntity[13328] was updated by another transaction concurrently
org.activiti.engine.ActivitiOptimisticLockingException: TimerEntity[13328] was updated by another transaction concurrently
at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:425)
at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:338)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:147)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:103)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
at org.activiti.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:59)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.jobexecutor.JobAcquisitionThread.run(JobAcquisitionThread.java:63)

GRAVE: exception during timer execution
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: org.activiti.engine.ActivitiException: unknown variable type name jpa-entity
### The error may involve org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.selectVariablesByExecutionId-Inline
### The error occurred while setting parameters
### Cause: org.activiti.engine.ActivitiException: unknown variable type name jpa-entity
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:77)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:172)
at org.activiti.engine.impl.persistence.entity.VariableInstanceManager.findVariableInstancesByExecutionId(VariableInstanceManager.java:47)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.loadVariableInstances(ExecutionEntity.java:876)
at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.ensureVariableInstancesInitialized(VariableScopeImpl.java:57)
at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:90)
at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:97)
at org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior.execute(CallActivityBehavior.java:67)

The same happens when I try to delete cascade my deployment on Activiti Probe: org.activiti.engine.ActivitiException: unknown variable type name jpa-entity

I'm sorry about my long post. I did my best to make myself clear.

Could you help me again? I'm using Activiti 5.6 and I'm going to try 5.7 latter.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
hahha… your initial post was very clear, but if you had searched a little, you probably would not have had to write it 🙂

Regarding your second question, it is always better not to use the same topic since that can be confusing. And there have been posts with kind of the same issue, so please search a little first and use a new topic afterwards

andregs
Champ in-the-making
Champ in-the-making
Thank you, Ronald. I have created a new topic: http://forums.activiti.org/en/viewtopic.php?f=6&t=2373