我们面临一个与spring @Transactional
相关的问题,我们有一个控制器和一个服务类,虽然服务类没有标记@Transactional
,实体正在保存。我们正在使用@EnableTransactionManagement(proxyTargetClass = true)
和OpenEntityManagerInViewInterceptor
spring data JPA 。我想这些信息可能还不够,但对这种行为的可能原因有什么了解。在实体持久性之前几乎没有日志
2016-01-07 20:58:15,393 DEBUG [org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource] (default task-23) Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2016-01-07 20:58:15,393 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (default task-23) Creating new transaction with name [org.springframework.data.envers.repository.support.EnversRevisionRepositoryImpl.save]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2016-01-07 20:58:15,394 DEBUG org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (default task-23) Skipping JTA sync registration due to auto join checking
2016-01-07 20:58:15,394 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (default task-23) Skipping JTA sync registration due to auto join checking
2016-01-07 20:58:15,394 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (default task-23) successfully registered Synchronization
2016-01-07 20:58:15,394 DEBUG [org.hibernate.jpa.spi.AbstractEntityManagerImpl] (default task-23) Looking for a JTA transaction to join
2016-01-07 20:58:15,394 DEBUG org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler] (default task-23) Joined JTA transaction
2016-01-07 20:58:15,394 DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory] (default task-23) Returning cached instance of singleton bean 'jpaAuditingHandler'
2016-01-07 20:58:15,417 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (smsQueueListenerBean-1) Initiating transaction commit
2016-01-07 20:58:15,417 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (smsQueueListenerBean-1) Creating new transaction with name [smsQueueListenerBean]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2016-01-07 20:58:15,418 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (emailQueueListenerBean-1) Initiating transaction commit
2016-01-07 20:58:15,418 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (emailQueueListenerBean-1) Creating new transaction with name [emailQueueListenerBean]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2016-01-07 20:58:15,459 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (default task-23) Participating in existing transaction
2016-01-07 20:58:15,459 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (default task-23) Participating in existing transaction
2016-01-07 20:58:15,460 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (default task-23) Obtaining JDBC connection
2016-01-07 20:58:15,461 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (default task-23) Obtained JDBC connection
2016-01-07 20:58:15,463 DEBUG [org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl] (default task-23) Starting ResultSet row #0
2016-01-07 20:58:15,463 DEBUG [org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl] (default task-23) On call to EntityIdentifierReaderImpl#resolve, EntityKey was already known; should only happen on root returns with an optional identifier specified
2016-01-07 20:58:15,464 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (default task-23) Releasing JDBC connection
2016-01-07 20:58:15,465 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (default task-23) Released JDBC connection
答案 0 :(得分:4)
总结我们在评论中讨论的内容: SimpleJpaRepository是JpaRepository接口的默认实现。如果我们看一下这个实现,我们可以看到,默认情况下,我们使用的是只读事务(对于像findAll这样的方法,...),对于删除或保存服务,它们都是用@transactional注释的。优质教育基金。