java事务问题
一个业务层里面有很多表的操作,a表允许脏读,b表不允许脏读这种事务怎么配置啊 在允许脏读的业务层该方法上加注解@Transactional(isolation =Isolation.READ_UNCOMMITTED) ,不允许的就用默认@Transactional 就行了,mysql默认是REPEATABLE_READ,可重复读。
也可以单独设置数据库的配置,mysql为例,select @@tx isolation;set session transaction isolation level read uncommitted;
@Service
public class TestService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Transactional(isolation = Isolation.READ_COMMITTED)
public List<Map<String,Object>> listForDirtyRead() {
List<Map<String,Object>> map = jdbcTemplate.queryForList("select * from tao");
return map;
}
} @Transactional
页:
[1]