应用程序异常被回滚异常覆盖-java.sql.SQLRecoverableException:IO错误:连接重置

时间:2020-05-14 19:59:27

标签: java spring spring-boot spring-data-jpa

使用Spring数据JPA执行查询时,堆栈跟踪中出现以下异常。

@Repository
@Transactional(rollbackFor = Exception.class)
public interface MyRequestsRepository extends JpaRepository<MyRequestsEntity,Integer>{

  @Modifying(clearAutomatically = true)
  public MyRequestsEntity saveAndFlush(MyRequestsEntity entity);


  @Modifying(clearAutomatically = true)
  @Query("update MyRequestsEntity rlre set rlre.status = ?1, rlre.errorMessage = ?2, rlre.endTime = ?3 where rlre.rpdLogRequestId = ?4")
  public void updateStatusAndErrorMessageAndEndDateByRequestId(Integer status, String errorMessage, Date endTime, Integer requestId);

}

MyRequestService.java

public class MyRequestService {

  @Autowired
  private MyRequestsRepository myRequestsRepository;

  public void processData(){
    myRequestsRepository.saveAndFlush(entity);

    Jsch call; // Approximately taking 10 - 15 mins

    // Getting an exception on executing the below query after 15 mins
    myRequestsRepository.updateStatusAndErrorMessageAndEndDateByRequestId(30,"error",new Date(),101);
  }
}

spring.datasource.hikari.maxLifetime=20000
spring.datasource.hikari.connectionTimeout=10000
spring.datasource.hikari.idleTimeout=15000
spring.datasource.hikari.minimumIdle=20

以下是我得到的例外情况:

Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210) ~[na:1.8.0_252]
    at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_252]
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) ~[na:1.8.0_252]
    at sun.security.ssl.InputRecord.read(InputRecord.java:503) ~[na:1.8.0_252]
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:990) ~[na:1.8.0_252]
    at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:948) ~[na:1.8.0_252]
    at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) ~[na:1.8.0_252]
    at oracle.net.ns.Packet.receive(Packet.java:311) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.net.ns.DataPacket.receive(DataPacket.java:105) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:305) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:249) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:171) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:89) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CMAREngineStream.unmarshalUB1(T4CMAREngineStream.java:429) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:397) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53) ~[ojdbc7-12.1.0.2.jar!/:na]
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:943) ~[ojdbc7-12.1.0.2.jar!/:na]
    ... 141 common frames omitted


org.springframework.transaction.TransactionSystemException: Could not roll back JPA transaction; nested exception is javax.persistence.PersistenceException: unexpected error when rollbacking
    at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:548) ~[spring-orm-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:853) ~[spring-tx-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:830) ~[spring-tx-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]

Caused by: java.sql.SQLException: Connection is closed
    at com.zaxxer.hikari.pool.ProxyConnection$ClosedConnection$1.invoke(ProxyConnection.java:472) ~[HikariCP-2.4.7.jar!/:na]
    at com.sun.proxy.$Proxy106.rollback(Unknown Source) ~[na:na]
    at com.zaxxer.hikari.pool.ProxyConnection.rollback(ProxyConnection.java:364) ~[HikariCP-2.4.7.jar!/:na]
    at com.zaxxer.hikari.pool.HikariProxyConnection.rollback(HikariProxyConnection.java) ~[HikariCP-2.4.7.jar!/:na]
    at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:115) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
    ... 123 common frames omitted

我们正在使用Springboot 1.4.2版本,Oracle 12c和Hikari 2.7.6

当我使用JDBCTemplate代替Spring数据JPA时,上述异常不会出现。还尝试了以下属性。但这没用。

spring.datasource.validationQuery=SELECT 1
spring.datasource.testOnBorrow=true

0 个答案:

没有答案