cancel
Showing results for 
Search instead for 
Did you mean: 

@TransactionConfiguration(defaultRollback = true) work not !

campa
Champ in-the-making
Champ in-the-making
Hi guys,

I'm using spring with activiti and I like to have unit tests that does not commit. But it seems committing also using @TransactionConfiguration(defaultRollback = true) .

Here the only important part of my code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/testApplicationContext.xml" }
@TransactionConfiguration(defaultRollback = true)
@Transactional
public class HelloProcessTest

       @Test
   public void simpleProcessTest() {
                DeploymentBuilder db = repositoryService.createDeployment();
      if (enableDuplicateFiltering) {
         db.enableDuplicateFiltering();
      }
      InputStream in = pDef.openStream();
      try {
         db.addInputStream(classPathUrl, in);
      } finally {
         IOUtils.closeQuietly(in);
      }
               db.deploy();
               runtimeService.startProcessInstanceByKey(ProcessDefintion.TEST_HELLO.getProcessName());
          Task task = taskService.createTaskQuery().singleResult();
               ….

      }

After that I found records into dbms ….

My spring configuration is like this:

<bean id="appDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:comp/env/jdbc/wgs" />
   </bean>
   
   <bean id="appEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="appDataSource" />
   </bean>
   
   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="appEmf" />
   </bean>
   <tx:annotation-driven transaction-manager="transactionManager" />
 
   <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

   <context:annotation-config />

Any ideas ? Where is my error ?

In my log I see:
20110623 152802 INFO  [org.springframework.test.context.transaction.TransactionalTestExecutionListener] (main) Began transaction (1): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@5c232697]; rollback [true]
20110623 152802 DEBUG [net.tinvention.edita21.wgs.mid.manager.WorkFlowManager] (main) deployng: /diagrams/test/hello.bpmn20.xml
20110623 152802 DEBUG [java.sql.Connection] (main) ooo Connection Opened
20110623 152802 DEBUG [java.sql.Connection] (main) ooo Connection Opened
20110623 152802 DEBUG [java.sql.PreparedStatement] (main) ==>  Executing: select * from ACT_GE_PROPERTY where NAME_ = ?
….

After begin transaction message, I see two new connections be opened without transaction begins messages … It seems are done by deploy action of activiti.

Any Ideas ?
Thx in advance.
4 REPLIES 4

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
how does your activity config look like:

http://www.activiti.org/userguide/index.html#N104EA

campa
Champ in-the-making
Champ in-the-making
I'm using also JPA, so the transactionManager is was configured as:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="appEmf" />
</bean>
But when I change it to 
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
             <property name="dataSource" ref="appDataSource" />
        </bean>
All seems working, also not committing tests configurations.

ProcessEngine in configuret as:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
     <property name="dataSource" ref="appDataSource" />
     <property name="transactionManager" ref="transactionManager" />
     <property name="databaseSchemaUpdate" value="true" />
    
     <property name="jpaEntityManagerFactory" ref="appEmf" />
     <property name="jpaHandleTransaction" value="true" />
     <property name="jpaCloseEntityManager" value="true" />
     <property name="jobExecutorActivate" value="true" />
  </bean>

I hope this is ok, and transactions are configured correctly .
JPA and non JPA activiti transactions are working on the same connection / transaction ?
What do you think ?

elsarfhem
Champ in-the-making
Champ in-the-making
up

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
up what?