Announcement Announcement Module
Collapse
No announcement yet.
Rollback not working with use of @Transactional Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rollback not working with use of @Transactional

    Hi,

    Although I have looked through the forum I have been unable to find a reply that resolves my issue - hence my own post.

    Here is the config:
    Code:
    <!-- Start: Datasources -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${app.jdbc.driverClassName}" />
            <property name="url" value="${app.jdbc.url}" />
            <property name="username" value="${app.jdbc.username}" />
            <property name="password" value="${app.jdbc.password}" />
        </bean>
    <!-- End: Datasources -->
          
          
          
        <!-- Start: Transaction Managers -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" scope="singleton">
            <property name="dataSource" ref="dataSource" />
        </bean>
        <tx:annotation-driven transaction-manager="transactionManager" />
    <!-- End: Transaction Managers -->


    And here is the class
    Code:
    @Transactional(rollbackFor = Throwable.class)
        public boolean execute(int userId) {
            logger.debug("userId=" + userId);
            
            boolean deleteUserRoleSuccessful = deleteUserRole(userId);
            boolean deleteUserSuccessful = deleteUser(userId);
            throw new RuntimeException("simulated Error condition");
            
            //return (deleteUserRoleSuccessful && deleteUserSuccessful);
        }


    Lastly, here is the log file
    Code:
    2014-03-13 13:59:08,980 HibernateTransactionManager [DEBUG] Using transaction object [org.springframework.orm.hi[email protected]6b611e]
    2014-03-13 13:59:08,980 HibernateTransactionManager [DEBUG] Creating new transaction with name [com.classifieds.services.DeleteUserService.execute]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-java.lang.Throwable
    2014-03-13 13:59:09,043 HibernateTransactionManager [DEBUG] Opened new Session [[email protected]] for Hibernate transaction
    2014-03-13 13:59:09,043 HibernateTransactionManager [DEBUG] Preparing JDBC Connection of Hibernate Session [[email protected]]
    2014-03-13 13:59:09,058 DriverManagerDataSource [DEBUG] Creating new JDBC DriverManager Connection to [jdbc:oracle:thin:@192.168.156.34:1521:JSDSOL04]
    2014-03-13 13:59:09,262 HibernateTransactionManager [DEBUG] Exposing Hibernate transaction as JDBC transaction [[email protected]]
    2014-03-13 13:59:09,262 TransactionSynchronizationManager [DEBUG] Bound value [[email protected]] for key [[email protected]6eb] to thread [http-8080-5]
    2014-03-13 13:59:09,262 TransactionSynchronizationManager [DEBUG] Bound value [[email protected]] for key [[email protected]] to thread [http-8080-5]
    2014-03-13 13:59:09,262 TransactionSynchronizationManager [DEBUG] Initializing transaction synchronization
    2014-03-13 13:59:09,262 TransactionInterceptor [DEBUG] Getting transaction for [com.classifieds.services.DeleteUserService.execute]
    2014-03-13 13:59:09,262 JdbcTemplate [DEBUG] Executing prepared SQL update
    2014-03-13 13:59:09,262 JdbcTemplate [DEBUG] Executing prepared SQL statement [delete from USER_ROLE where USER_ID=?]
    2014-03-13 13:59:09,262 DataSourceUtils [DEBUG] Fetching JDBC Connection from DataSource
    2014-03-13 13:59:09,262 DriverManagerDataSource [DEBUG] Creating new JDBC DriverManager Connection to [jdbc:oracle:thin:@192.168.156.34:1521:JSDSOL04]
    2014-03-13 13:59:09,449 DataSourceUtils [DEBUG] Registering transaction synchronization for JDBC Connection
    2014-03-13 13:59:09,449 TransactionSynchronizationManager [DEBUG] Bound value [[email protected]] for key [[email protected]09] to thread [http-8080-5]
    2014-03-13 13:59:09,449 TransactionSynchronizationManager [DEBUG] Retrieved value [[email protected]] for key [[email protected]09] bound to thread [http-8080-5]
    2014-03-13 13:59:09,449 StatementCreatorUtils [DEBUG] Setting SQL statement parameter value: column index 1, parameter value [562], value class [java.lang.Integer], SQL type unknown
    2014-03-13 13:59:09,465 JdbcTemplate [DEBUG] SQL update affected 1 rows
    2014-03-13 13:59:09,465 TransactionSynchronizationManager [DEBUG] Retrieved value [[email protected]] for key [[email protected]09] bound to thread [http-8080-5]
    2014-03-13 13:59:09,465 JdbcTemplate [DEBUG] Executing prepared SQL update
    2014-03-13 13:59:09,465 JdbcTemplate [DEBUG] Executing prepared SQL statement [delete from USERS where USER_ID=?]
    2014-03-13 13:59:09,465 TransactionSynchronizationManager [DEBUG] Retrieved value [[email protected]] for key [[email protected]09] bound to thread [http-8080-5]
    2014-03-13 13:59:09,465 TransactionSynchronizationManager [DEBUG] Retrieved value [[email protected]] for key [[email protected]09] bound to thread [http-8080-5]
    2014-03-13 13:59:09,465 StatementCreatorUtils [DEBUG] Setting SQL statement parameter value: column index 1, parameter value [562], value class [java.lang.Integer], SQL type unknown
    2014-03-13 13:59:09,480 JdbcTemplate [DEBUG] SQL update affected 1 rows
    2014-03-13 13:59:09,480 TransactionSynchronizationManager [DEBUG] Retrieved value [[email protected]] for key [[email protected]09] bound to thread [http-8080-5]
    2014-03-13 13:59:09,480 TransactionInterceptor [DEBUG] Completing transaction for [com.classifieds.services.DeleteUserService.execute] after exception: java.lang.RuntimeException: simulated Error condition
    2014-03-13 13:59:09,480 RuleBasedTransactionAttribute [DEBUG] Applying rules to determine whether transaction should rollback on java.lang.RuntimeException: simulated Error condition
    2014-03-13 13:59:09,480 RuleBasedTransactionAttribute [DEBUG] Winning rollback rule is: RollbackRuleAttribute with pattern [java.lang.Throwable]
    2014-03-13 13:59:09,480 HibernateTransactionManager [DEBUG] Triggering beforeCompletion synchronization
    2014-03-13 13:59:09,480 TransactionSynchronizationManager [DEBUG] Removed value [[email protected]] for key [[email protected]09] from thread [http-8080-5]
    2014-03-13 13:59:09,480 DataSourceUtils [DEBUG] Returning JDBC Connection to DataSource
    So, in my config, I am sure that I am creating an org.springframework.jdbc.datasource.DataSourceTran sactionManager. In the log output though, it looks as though a Hibernate Transaction is getting created:

    2014-03-13 13:59:08,980 HibernateTransactionManager [DEBUG] Creating new transaction with name [com.classifieds.services.DeleteUserService.execute]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-java.lang.Throwable

    ... and then this gets exposed as a JDBC transaction

    2014-03-13 13:59:09,262 HibernateTransactionManager [DEBUG] Exposing Hibernate transaction as JDBC transaction [[email protected]]

    ...so I am not sure why my transaction DOES NOT roll back.

    I would be very grateful fo

  • #2
    OK...I figured this out...

    I actually had another transactionManager configured elsewhere in my config. It had the same name 'transactionManager', but it was configured to point to a Hibernate datasource. Once I found that I got my rollbacks working fine.

    Comment

    Working...
    X