Results 1 to 2 of 2

Thread: Transactions appear to be rolled back, but they are not rolled back in the database.

  1. #1

    Default Transactions appear to be rolled back, but they are not rolled back in the database.

    PersistenceHelper-context.xml
    Code:
       <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">    <!---->
            <property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver"/>
            <property name="url" value="jdbc:hsqldb:mem:mydb"/>
            <property name="username" value="sa"/>
            <property name="password" value=""/>
        </bean>
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
              depends-on="dataSource" name="_sessFac" >  
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="hibernate.cfg.xml.incDTD"/>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                    <prop key="hibernate.hbm2ddl.auto">create</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.connection.shutdown">true</prop>
                </props>
            </property>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
    class header
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"classpath:PersistenceHelper-context.xml"})
    @TransactionConfiguration(defaultRollback = true, transactionManager = "transactionManager") 
    @Transactional
    public class BaseClass extends BaseTestClass{//.....}
    And then all of my classes that I want to use transactions all derive from BaseClass, i.e.
    Code:
    public class FooTest extends BaseClass
    Also, when I run my code, I see the following:

    Code:
    HibernateTransactionManager | Initiating transaction rollback
    [13 Jul 2012 11:29:13,738] DEBUG  HibernateTransactionManager | Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@107536b]
    [13 Jul 2012 11:29:13,738] DEBUG  HibernateTransactionManager | Triggering afterCompletion synchronization
    [13 Jul 2012 11:29:13,738] DEBUG  TransactionSynchronizationManager | Clearing transaction synchronization
    [13 Jul 2012 11:29:13,738] DEBUG  TransactionSynchronizationManager | Removed value [org.springframework.orm.hibernate3.SessionHolder@17b3cdb] for key [org.hibernate.impl.SessionFactoryImpl@14642ac] from thread [main]
    [13 Jul 2012 11:29:13,738] DEBUG  TransactionSynchronizationManager | Removed value [org.springframework.jdbc.datasource.ConnectionHolder@129a6a3] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@c506b] from thread [main]
    [13 Jul 2012 11:29:13,738] DEBUG  HibernateTransactionManager | Closing Hibernate Session [org.hibernate.impl.SessionImpl@107536b] after transaction
    [13 Jul 2012 11:29:13,738] DEBUG  SessionFactoryUtils       | Closing Hibernate Session
    [13 Jul 2012 11:29:13,738] INFO   TransactionalTestExecutionListener | Rolled back transaction after test execution for test context
    Yet when I delete from my database, the change is persisted and my future tests fail because there is a missing object from the table. Am I missing something? Any direction would be much appreciated. Thanks in advance!!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Post your hibernate configuration file and post the code that is modifying the data and a bit more of your test case.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •