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

Quarkus JPA Hibernate Statistics show multiple connections being used under the same transaction

我有一个使用 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 次来自连接池的请求。您所做的每个查询都可以在一个语句中完成,因此您将查询与连接的用法相同。