org.springframework.transaction.UnexpectedRollbackException: JTA transaction already rolled back (pr

org.springframework.transaction.UnexpectedRollbackException: JTA transaction already rolled back (probably due to a timeout)

错误原因默认的Spring 默认的事务是 tomeout 是 -1

在这里插入图片描述

原因是 这里使用Spring 默认事务

java int timeout() default -1;

sql 查询时间长 再加上入库时间 超出了默认的时间范围

所以抛出了 UnexpectedRollbackException 异常
打印 JTA transaction already rolled back (probably due to a timeout) 错误

解决办法:

  • 设置超时间时间 长点
    java @Transactional(rollbackFor = Exception.class,timeout = 60)
  • 将插入语句分离出去,将事务加到插入语句中
  • 优化sql 减少查询时间
发布了241 篇原创文章 · 获赞 66 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/weixin_38361347/article/details/103460508