---
title: "使用@Transactional时候的注意点"
author: "jakoes"
date: "2010-10-11T18:21:04Z"
tags: []
categories: ["企业架构"]
slug: "transactional"
draft: false
lastmod: "2010-10-11T18:21:04Z"
id: 781705
url: "https://jakoes.iteye.com/blog/781705"
---

使用@Transactional时候的注意点：
1.确认有如下配置：<tx:annotation-driven transaction-manager="transactionManager"/>
2.readOnly能不用就不能
3.嵌套事务中尽量少用REQUIRED_NEW，除非某些操作无论如何都要持久化
4.只有uncheck exception才会使事务回滚，checked exception不会使用回滚。如果要在checked exception中让事务回滚，则有如下方法：
  a)在属性rollbackFor中增加unchecked exception，如：@Transactional(rollbackFor={Exception.class})
  b)手工把checked exception默译成unchecked exception