Spring Data JPA Quick Guide
  • Spring Data JPA 快速指南
  • 配置依赖
  • 配置数据源
  • 数据库编码与词语定序
  • Core Concepts
  • 基本用法
  • Transactions
    • 什么是事务
    • 配置事务(@EnableTransactionManagement)
    • 配置事务(XML)
    • 配置事务(@Transactional)
    • @Transactional 实现细节
    • Transaction and Spring Data JPA
    • 事务隔离
    • 事务传播
  • Query Creation from Method Names
  • Using @Query
  • Sorting and Pagination
  • Projection
  • Specification
  • Query by Example
  • javax.persistence Annotations
    • @OneToOne (bidirectional)
      • Usage
      • PO Serialization
      • Save and Update
      • Nested Projection
      • @MapsId
    • @OneToMany (bidirectional)
    • @OneToMany (unidirectional)
    • @ManyToMany (bidirectional)
      • Many-to-Many Using a Composite Key
由 GitBook 提供支持
在本页
  1. Transactions

配置事务(@EnableTransactionManagement)

Spring 3.1 支持了 @EnableTransactionManagement 注解,可以在 @Configuration 修饰的配置类中开启注解事务支持。

@Configuration
@EnableTransactionManagement
public class PersistenceJPAConfig{

    @Bean
    public LocalContainerEntityManagerFactoryBean
        entityManagerFactoryBean(){
        //...
    }

    @Bean
    public PlatformTransactionManager transactionManager(){
        JpaTransactionManager transactionManager
            = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(
            entityManagerFactoryBean().getObject() );
        return transactionManager;
    }
}

如果我们使用的是 Spring Boot,那么该事务管理功能则会被自动开启。

上一页什么是事务下一页配置事务(XML)

最后更新于3年前