如下代码,springboot操作oracle,操作事务为什么不起作用?

@Service
public class VersionServiceImpl implements VersionServiceI {

    @Autowired
    VersionMapper versionMapper;

    @Override
    public Version selectByPrimaryKey(String type) {
        Version version = versionMapper.selectByPrimaryKey(type);
        return version;
    }

    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
    @Override
    public int updateByPrimaryKeySelective(Version record) {
        int i = versionMapper.updateByPrimaryKeySelective(record);
        return i;
    }

    @Override
    public String getMsgId() {
        int msgId = versionMapper.getMsgId();
        return String.format("%06d", msgId);
    }

}
阅读 2.5k
1 个回答

spring的@Transactional是基于bean的aop的,要用其他bean比如controller调用@Transactional的service方法,异常类型要是RuntimeExceiton才能,否则要@Transactional(rollbackFor=Exception.class)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题