Spring Data JPA闭合连接
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Data JPA闭合连接相关的知识,希望对你有一定的参考价值。
[有一个功能,首先在数据库中插入状态为“正在运行”的记录,然后进行一些长时间的处理,最后将状态更新为“成功”或“失败”。
由于处理时间过长(将数据上传到第三方应用程序需要4个小时),因此在更新状态时最终出现错误,]。>
java.sql.BatchUpdateException: ORA-02396: exceeded maximum idle time, please connect again SQL: update STATUS set status=? o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-02396: exceeded maximum idle time, please connect again ERROR [-,f292b6c9becb8716,f292b6c9becb8716,false] 13556 --- [nio-8080-exec-7] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.GenericJDBCException: could not execute batch] WARN [-,f292b6c9becb8716,f292b6c9becb8716,false] 13556 --- [nio-8080-exec-7] com.zaxxer.hikari.pool.ProxyConnection : HikariPool-2 - Connection oracle.jdbc.driver.T4CConnection@7fb2645b marked as broken because of SQLSTATE(08003), ErrorCode(17008) java.sql.SQLRecoverableException: Closed Connection at oracle.jdbc.driver.PhysicalConnection.getAutoCommit(PhysicalConnection.java:1828) at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1953) at com.zaxxer.hikari.pool.ProxyConnection.rollback(ProxyConnection.java:377) at com.zaxxer.hikari.pool.HikariProxyConnection.rollback(HikariProxyConnection.java) at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:116) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.rollback(JdbcResourceLocalTransactionCoordinatorImpl.java:251) at org.hibernate.engine.transaction.internal.TransactionImpl.rollback(TransactionImpl.java:100)
我如何处理这种情况?
下面是我的代码段:
public void upload() {
entity.setStatus("RUNNING");
repository.save(entity);
try {
//Uploads data to thrid party;
callingThridPartyApp();
log.info("Upload successfull.");
entity.setStatus("SUCCESS");
repository.save(entity);
} catch (Exception e) {
log.error("Upload failed.", e);
entity.setStatus("FAILED");
repository.save(entity);
}
}
[有一个功能可以在数据库中插入状态为“正在运行”的记录,然后开始进行长时间的处理,最后将状态更新为“成功”或“失败”。我正在得到...
答案
我通过在更新数据库状态的漫长过程结束时声明新事务来解决此问题。
以上是关于Spring Data JPA闭合连接的主要内容,如果未能解决你的问题,请参考以下文章