AnsweredAssumed Answered

flush without tx.begin() - problem with JPA variable

Question asked by p4w3l on Apr 6, 2012
I try simple JPA configuration with tested JPA classes and persistence.xml. I am not sure if it is importand but it works standalone with: EclipseLink 2.3.2, Tomcat 6. When added 3 lines to activiti-context.xml from user manual and simply: find an object from em, put into variables map and start a process I receive error exception with:

javax.persistence.TransactionRequiredException: 
Exception Description: No transaction is currently active
   org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.throwCheckTransactionFailedException(EntityTransactionWrapper.java:113)
   org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.checkForTransaction(EntityTransactionWrapper.java:50)
   org.eclipse.persistence.internal.jpa.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:1776)
   org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:780)
   org.activiti.engine.impl.variable.EntityManagerSessionImpl.flush(EntityManagerSessionImpl.java:54)
   org.activiti.engine.impl.variable.JPAEntityVariableType.setValue(JPAEntityVariableType.java:61)

It looks for me that EntityManagerSessionImpl never begins the transaction. Here below are fragments that may say more about my case:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
     <property name="jndiName" value="java:comp/env/jdbc/bpm"/>
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="jpaPersistenceUnitName" value="default" />
    <property name="jpaHandleTransaction" value="true" />
    <property name="jpaCloseEntityManager" value="true" />

<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
      <non-jta-data-source>java:comp/env/jdbc/sam</non-jta-data-source>
      <class>sam.Address</class>

Except JPA variables that I have just wanted to add to project - everything else works fine. I can manage to use Activiti and JPA independently. Just started to evaluate JPA variables I got stucked with that flush() that has no active transaction.

After analisys of two code of: org.activiti.engine.impl.variable.EntityManagerSessionImpl and org.activiti.engine.impl.variable.JPAEntityVariableType it looks for me that somehow the code finds the transaction active what cannot be true after my simple em.find(…) and trying flush without first tx.begin().

Is this maybe a bug to report? Would you please test a simple JPA variable without any special JTA like in my case and give me configuration example?

Outcomes