我正在运行一个带有 hibernate 和 spring-data 的 spring-boot 应用程序。二、有以下方法:
@Service
class SomeService(private val repository : SomeRepository){
fun someEndPoint(request: Request, Id: Long): UUID? {
return try {
val enNumber = repository.callEncrypt(request.accountNumber)
val entity = SomeEntity().apply{
this.id = Id
this.enNumber = enNumber
}
repository.save(entity)
} catch (e: Exception) {
LOGGER.error("someEndPoint",e)
throw e
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我第四次运行此方法时,出现无法获取 JDBC 连接异常。我怀疑当我调用存储过程“callEncrypt”时,hibernate 不会在工作完成后释放连接,因为如果我删除该行,应用程序运行良好,由于 hibernate 正在处理事务,因此无法手动关闭连接(并且没有理由这样做),所以我已经坚持了一段时间,我不知道会发生什么。
奇怪的是,当我使用 sp_who 过程在 sql server 中查找活动连接时,没有活动连接,我现在唯一的解决方案是重新启动应用程序。如果我重新启动应用程序一切正常,直到我再次运行这个函数第四次,所以很明显 hibernate 永远不会释放连接。
这是完整的堆栈跟踪:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Unable …Run Code Online (Sandbox Code Playgroud)