Spring Boot +可序列化交易问题

时间:2019-03-09 16:43:19

标签: java mysql hibernate spring-boot

您好,我在Java + Spring中遇到交易问题。基本上,问题是当我在应用程序中测试并发帖子时,有时插入多个行(有时),而有时会出现此错误:

  

2019-03-09 13:30:23.096警告20820 --- [nio-8080-exec-7]   o.h.engine.jdbc.spi.SqlExceptionHelper:SQL错误:0,SQLState:   空2019-03-09 13:30:23.096 WARN 20820 --- [nio-8080-exec-9]   o.h.engine.jdbc.spi.SqlExceptionHelper:SQL错误:0,SQLState:   null 2019-03-09 13:30:23.096错误20820 --- [nio-8080-exec-7]   o.h.engine.jdbc.spi.SqlExceptionHelper:HikariPool-1-连接   不可用,请求在30004ms后超时。 2019-03-09   13:30:23.096错误20820-[nio-8080-exec-9]   o.h.engine.jdbc.spi.SqlExceptionHelper:HikariPool-1-连接   不可用,请求在30004ms后超时。 2019-03-09   13:30:23.096 WARN 20820 --- [nio-8080-exec-5]   o.h.engine.jdbc.spi.SqlExceptionHelper:SQL错误:0,SQLState:   空....

我的方法非常简单:

@Transactional(isolation = Isolation.SERIALIZABLE)
public SeatReservation saveOrException(SeatReservation entity) {
    if (!seatReservationDao.existsByUuid(uuid)) {
        entity.setUuid(uuid);
        return seatReservationDao.save(entity);
    }
    return null;
}

我知道还有其他方法可以做到这一点,但是我试图理解为什么我要使用Isolation.SERIALIZABLE不能同时执行一次事务。

这是日志:

  

休眠:       选择           seatreserv0_.id为col_0_0_       从           预订seatreserv0_       哪里           seatreserv0_.uuid =?极限?

     

休眠:       选择           seatreserv0_.id为col_0_0_       从           预订seatreserv0_       哪里           seatreserv0_.uuid =?极限?

     

休眠:       选择           seatreserv0_.id为ID1_0_0_,           seatreserv0_。到达后到达2_0_0_,           seatreserv0_.departure作为departur3_0_0_,           seatreserv0_.email作为电子邮件4_0_0_,           seatreserv0_.last_name为last_nam5_0_0_,           seatreserv0_.name为name6_0_0_,           seatreserv0_.uuid作为uuid7_0_0_       从           预订seatreserv0_       哪里           seatreserv0_.id =?

     

休眠:       选择           seatreserv0_.id为ID1_0_0_,           seatreserv0_。到达后到达2_0_0_,           seatreserv0_.departure作为departur3_0_0_,           seatreserv0_.email作为电子邮件4_0_0_,           seatreserv0_.last_name为last_nam5_0_0_,           seatreserv0_.name为name6_0_0_,           seatreserv0_.uuid作为uuid7_0_0_       从           预订seatreserv0_       哪里           seatreserv0_.id =?

它将执行所有读取,然后执行所有保存。奇怪

谢谢!

0 个答案:

没有答案