Quarkus JPA Hibernate Statistics显示同一事务下正在使用多个连接

问题描述

我有一个使用quarkus和hibernate访问postgresql数据库的项目。做一些测试,我发现每个请求的休眠统计信息报告每个请求正在使用多个连接。我虽然在同一事务的后台执行的所有查询都将使用相同的物理连接,但是我不确定这是否正在发生。

我已经提供了一个示例here,在这里下载并执行测试将具有相同的行为。该测试将执行并结束在同一事务中执行同一查询四次的端点

基于这段代码:

2020-08-21 16:28:13,079 INFO  [org.hib.eng.int.StatisticalLoggingSessionEventListener] (executor-thread-1) Session Metrics {
    5371760 nanoseconds spent acquiring 4 JDBC connections;
    61585 nanoseconds spent releasing 4 JDBC connections;
    18094275 nanoseconds spent preparing 4 JDBC statements;
    19146452 nanoseconds spent executing 4 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

有人知道JDBC连接是指向数据库的物理连接,还是仅仅知道实体管理器已请求四次连接到连接池?

谢谢。

解决方法

来自连接池的

4次请求。您所做的每个查询都可以在一个语句中完成,因此您为什么要使用查询作为连接。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...