SpringBoot应用程序引发异常
Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
在对API的若干请求之后
public Response getChainObjectDepartments(@RequestBody List<UUID> ids) {
val ud = QUserDepartmentPlain.userDepartmentPlain;
val d = QDepartmentPlain.departmentPlain;
val result = jpaQueryFactory.select(d).from(d).join(ud).on(ud.departmentId.eq(d.id)).where(ud.userId.in(ids)).transform(
groupBy(ud.userId).as(GroupBy.list(d))
);
return Response.ok(result);
}
我使用PostgreSQL和pgAdmin显示了会话的最后一个查询是由这个QueryDSL查询生成的:
select
userdepart1_."user_id" as col_0_0_,
department0_."id" as col_1_0_,
department0_."id" as id1_29_,
department0_."charge_leader_id" as charge_11_29_,
department0_."dingtalk_id" as dingtalk2_29_,
department0_."is_audit" as is_audi12_29_,
department0_."is_enable" as is_enabl3_29_,
department0_."name" as name4_29_,
department0_."parent_id" as parent_i5_29_,
department0_."remark" as remark6_29_,
department0_."sort" as sort7_29_,
department0_."tz_create" as tz_creat8_29_,
department0_."tz_retire" as tz_retir9_29_,
department0_."tz_update" as tz_upda10_29_
from
"organization"."department" department0_
inner join
"organization"."rel_user_department" userdepart1_
on (
userdepart1_."department_id"=department0_."id"
)
where
userdepart1_."user_id" in (
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?
)
当所有会话填充此查询时,应用程序开始抛出异常Unable to acquire JDBC Connection
最后,我通过在函数中添加@Transactional来解决这个问题(一般情况下,只有选择查询时,我不会在函数中添加@Transactional),但我仍然不知道这个QueryDSL查询有什么问题,为什么它必须有@Transactional。
1条答案
按热度按时间fruv7luv1#
实际上,这个问题是已知的。当在事务外部使用FetchableQueryBase#transform时,存在连接泄漏。
在此检查:https://github.com/querydsl/querydsl/issues/3089