2 Replies Latest reply on Mar 18, 2013 6:21 PM by dimas_

    Strange behaviour of transaction when using Arquillian's Persistence Extension

    dimas_

      Hello All,

       

      I wrote a little test project to learn Arquillian and its facilities. Now I am trying to understand how Arquillian's Persistence Extension is working and I faced with some strange behaviour. At least it seems to me so). Here is details:

       

      I have simple test method:

       

       

      @RunWith(Arquillian.class)
      @Cleanup(phase = TestExecutionPhase.NONE)
      public class ItemFacadeTest {
      
           @EJB
           private ItemFacadeLocal facade;
      
           ...
      
           @Test
           @Transactional
           public void testAutomaticTransactionRollbackAfterException() {
                Item item = new Item();
                item.setName("testTransactionRollback");
      
                facade.persistItem(item);
      
                throw new RuntimeException();
           }
      }
      
      

       

      As you can see test method is wrapped with transaction. TransactionMode is COMMIT by default. In this method I explicitly throw an exception and I expect that transaction will be rolled back after exception. But changes still in the DB after exception have been thrown. If I set TransactionMode=ROLLBACK then all is rolled back as it should be.

       

      Is this correct behavior? Because I think that transaction should roll back after exception have been thrown.

       

      By the way, I also tested Arquillian's Transaction Extension and there transaction is rolling back after exception have occured. But I faced another issue with Transaction Extension wich I will describe in another question.

       

      My arquillian.xml file is:

       

       

      <arquillian xmlns="http://jboss.org/schema/arquillian"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="
              http://jboss.org/schema/arquillian
              http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
          <container qualifier="jbossas-7-managed" default="true">
              <configuration>
                  <property name="jbossHome">D:\Programs\jboss-as-7.1.1.Final</property>
                  <property name="serverConfig">standalone-full.xml</property>
                  <property name="allowConnectingToRunningServer">true</property> 
              </configuration>
             <protocol type="Servlet 3.0"/>
          </container>
               <extension qualifier="persistence">
                    <property name="defaultDataSource">java:/mydb</property>
                    <property name="userTransactionJndi">java:jboss/UserTransaction</property>
                </extension>
                <extension qualifier="persistence-dbunit">
                    <property name="datatypeFactory">org.dbunit.ext.mssql.MsSqlDataTypeFactory</property>
                    <property name="useIdentityInsert">true</property>
                    <property name="excludePoi">true</property>
                    <property name="dataSeedStrategy">REFRESH</property>
                </extension>
                 <extension qualifier="transaction">
                    <property name="manager">java:jboss/UserTransaction</property>
                  </extension>
      </arquillian>