Мне нужен совет по настройке Spring, JTA, источника данных и транзакций: @Transactional (Propagation = REQUIRES_NEW)
работает неправильно.
У меня @Transactional
для метода менеджера и метод для введенного второго менеджера @Transactional(propagation = REQUIRES_NEW)
называется.
Если внешняя транзакция откатывается (с помощью исключения RuntimeException), я ожидаю, что изменения, сделанные во внутренней транзакции, будут сохранены. Но этого не происходит, внутренняя транзакция вообще не фиксируется.
В журнале говорится: JtaTransactionManager - Initiating transaction commit
, но commit () не вызывается в драйвере JDB C.
Драйвер JDB C вызывается только при откате внешней транзакции - и вызывается только откат.
Настройка: JBoss EAP 7, Spring 5.1, ojdb c источник данных в автономном режиме. xml, с jta = Истинный источник данных, внедренный через JNDI (WildFlyDataSource), autoCommit = false.
Журнал:
11:10:23,725 INFO [stdout] (default task-1) DEBUG DataSourceUtils - Registering transaction synchronization for JDBC Connection
11:10:23,732 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@248c2848] for key [org.jboss.as.connector.subsystems.datasources.WildFlyDataSource@43dd288] to thread [default task-1]
11:10:23,733 INFO [stdout] (default task-1) DEBUG SQLInsertClause - update APPLICATION_REQUEST set APP_REQ_STATUS = ?, APP_REQ_SUB_STATUS = ?, REJECTIONREASON = ? where APPLICATION_REQUEST.APPLICATION_ID = ?
11:10:23,734 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [Connection] prepareStatement(update APPLICATION_REQUEST
set APP_REQ_STATUS = ?, APP_REQ_SUB_STATUS = ?, REJECTIONREASON = ?
where APPLICATION_REQUEST.APPLICATION_ID = ?)
11:10:23,735 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] setString(1, REJECTED)
11:10:23,736 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] setString(2, REJECTED)
11:10:23,740 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] setLong(3, 1)
11:10:23,742 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] setLong(4, 461)
11:10:23,748 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] setQueryTimeout(299)
11:10:23,749 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] executeUpdate()
11:10:23,768 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [PreparedStatement] close()
11:10:23,769 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [Connection] isClosed()
11:10:23,770 INFO [stdout] (default task-1) INFO StatisticLogger - DB, 36, update
11:10:23,771 INFO [stdout] (default task-1) DEBUG ApplicationRequestDaoImpl - DAO updateApplication - number of updated records is: 1
11:10:23,771 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@248c2848] for key [org.jboss.as.connector.subsystems.datasources.WildFlyDataSource@43dd288] bound to thread [default task-1]
11:10:23,774 INFO [stdout] (default task-1) TRACE JtaTransactionManager - Triggering beforeCommit synchronization
11:10:23,778 INFO [stdout] (default task-1) TRACE JtaTransactionManager - Triggering beforeCompletion synchronization
11:10:23,779 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@248c2848] for key [org.jboss.as.connector.subsystems.datasources.WildFlyDataSource@43dd288] from thread [default task-1]
11:10:23,780 INFO [stdout] (default task-1) DEBUG DataSourceUtils - Returning JDBC Connection to DataSource
11:10:23,781 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [Connection] close()
11:10:23,782 INFO [stdout] (default task-1) DEBUG JtaTransactionManager - Initiating transaction commit
11:10:23,784 INFO [stdout] (default task-1) TRACE JtaTransactionManager - Triggering afterCommit synchronization
11:10:23,785 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Clearing transaction synchronization
11:10:23,786 INFO [stdout] (default task-1) TRACE JtaTransactionManager - Triggering afterCompletion synchronization
>>>HERE I WOULD EXPECT INNER TRX BE COMMITED<<<
11:10:23,787 INFO [stdout] (default task-1) DEBUG JtaTransactionManager - Resuming suspended transaction after completion of inner transaction
11:10:23,788 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Initializing transaction synchronization
11:10:23,792 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@5a3f13a] for key [org.jboss.as.connector.subsystems.datasources.WildFlyDataSource@43dd288] to thread [default task-1]
11:10:23,803 INFO [stdout] (default task-1) TRACE TransactionInterceptor - Completing transaction for [MyController.method] after exception: MyValidationException: Validation failed.
11:10:23,805 INFO [stdout] (default task-1) TRACE RuleBasedTransactionAttribute - Applying rules to determine whether transaction should rollback on MyValidationException: Validation failed.
11:10:23,807 INFO [stdout] (default task-1) TRACE RuleBasedTransactionAttribute - Winning rollback rule is: null
11:10:23,808 INFO [stdout] (default task-1) TRACE RuleBasedTransactionAttribute - No relevant rollback rule found: applying default rules
11:10:23,813 INFO [stdout] (default task-1) TRACE JtaTransactionManager - Triggering beforeCompletion synchronization
11:10:23,815 INFO [stdout] (default task-1) DEBUG JtaTransactionManager - Initiating transaction rollback
11:10:23,838 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Clearing transaction synchronization
11:10:23,840 INFO [stdout] (default task-1) TRACE JtaTransactionManager - Triggering afterCompletion synchronization
11:10:23,841 INFO [stdout] (default task-1) TRACE TransactionSynchronizationManager - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@5a3f13a] for key [org.jboss.as.connector.subsystems.datasources.WildFlyDataSource@43dd288] from thread [default task-1]
11:10:23,842 INFO [stdout] (default task-1) DEBUG DataSourceUtils - Returning JDBC Connection to DataSource
11:10:23,843 DEBUG [jboss.jdbc.spy] (default task-1) java:/jdbc/myDS [Connection] close()