Spring手动提交事务

  

// name的值根据spring配置文件的事物管理器的id而定
@Resource(name="transactionManager")
private DataSourceTransactionManager transactionManager; public boolean save(Entity e) {
DefaultTransactionDefinition transDefinition = new DefaultTransactionDefinition();
   transDefinition.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus transStatus = transactionManager.getTransaction(transDefinition);
try {
  /**
    写自己的操作数据库的代码
  /
  transactionManager.commit(transStatus);
} catch (Exception e) {
transactionManager.rollback(transStatus);
} }
上一篇:httpcomponents-client-4.3.x DOC


下一篇:QT高级线程API总结(一)QtConcrrent::run()