【问题标题】:maintaining transcations in spring jdbc template在spring jdbctemplate中维护事务
【发布时间】:2011-09-25 17:49:52
【问题描述】:

假设我想在 10 个不同的表中插入记录,这应该是原子的,意味着所有插入都应该发生在所有表中,或者没有。如何在 spring jdbc 模板中维护这种事务?

【问题讨论】:

    标签: java spring transactions spring-jdbc


    【解决方案1】:
    • 在 applicationContext 中定义数据源
    • 创建将使用 JdbcTemplate 进行插入的 dao 类
    • 创建一个调用 dao 类的插入方法的服务类
    • 使用@Transactional 注释服务类
    • <tx:annotation-driven/> 添加到您的applicationContext 并定义一个引用您的数据源的transactionManager

    参见参考here 和示例here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      相关资源
      最近更新 更多