[JIRA] (HHH-16469) Hibernate repeatedly issues identical SELECT queries to load an optional one-to-one association
by Puhong You (JIRA)
Puhong You ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-16469 ( https://hibernate.atlassian.net/browse/HHH-16469?atlOrigin=eyJpIjoiYjFiNj... )
Re: Hibernate repeatedly issues identical SELECT queries to load an optional one-to-one association ( https://hibernate.atlassian.net/browse/HHH-16469?atlOrigin=eyJpIjoiYjFiNj... )
Hi, Andrea,
Thanks for the update.
I downloaded your test class HHH-16469Test.java, and copied my entity beans into it, it loaded the Agency with just 4 queries you listed. However when I ran my test outside of your test class, I saw the extra queries I reported originally –
[04/20/23 15:23:11.139] DEBUG : main : SQL - select t1_0.AGENCY_ID,a1_0.AGENCY_ID,a1_0.AGENCY_DETAIL,t1_0.AGENCY_NAME from TEST.AGENCY t1_0 left join TEST.AGENCY_DETAIL a1_0 on a1_0.AGENCY_ID=t1_0.AGENCY_ID where t1_0.AGENCY_ID=?
[04/20/23 15:23:11.140] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.292] DEBUG : main : SQL - select u1_0.AGENCY_ID,u1_0.USER_ID,u1_0.USER_NAME from TEST.USER u1_0 where u1_0.AGENCY_ID=?
[04/20/23 15:23:11.292] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.388] DEBUG : main : SQL - select g1_0.AGENCY_ID,g1_0.GROUP_ID,g1_0.GROUP_NAME from TEST.GROUP g1_0 where g1_0.AGENCY_ID=?
[04/20/23 15:23:11.388] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.499] DEBUG : main : SQL - select u1_0.GROUP_ID,u1_1.USER_ID,a1_0.AGENCY_ID,a1_0.AGENCY_NAME,u1_1.USER_NAME from TEST.GROUP_USER u1_0 join TEST.USER u1_1 on u1_1.USER_ID=u1_0.USER_ID left join TEST.AGENCY a1_0 on a1_0.AGENCY_ID=u1_1.AGENCY_ID where u1_0.GROUP_ID in(select g1_0.GROUP_ID from TEST.GROUP g1_0 where g1_0.AGENCY_ID=? )
[04/20/23 15:23:11.499] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.558] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:11.558] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.649] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:11.649] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.739] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:11.740] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.837] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:11.837] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:11.937] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:11.937] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:12.037] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:12.037] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:12.137] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:12.137] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
[04/20/23 15:23:12.237] DEBUG : main : SQL - select t1_0.AGENCY_ID,t1_0.AGENCY_DETAIL from TEST.AGENCY_DETAIL t1_0 where t1_0.AGENCY_ID=?
[04/20/23 15:23:12.237] TRACE : main : bind - binding parameter [1] as [INTEGER] - [1]
As you can see, the first 3 queries are identical to yours. However the 4th query ( SELECT FROM TEST.GROUP_USER ) (in red above) does not join with the AGENCY_DETAIL table in my case, and that resulted in the extra 8 subsequent ( SELECT FROM TEST.AGENCY_DETAIL ) queries. I will continue to look at my end. Can you think of a code path where Hibernate generates these extra select queries? I am running hibernate 6.2.1.Final on JDK 20.
( https://hibernate.atlassian.net/browse/HHH-16469#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16469#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100222- sha1:57eb20e )
1 year, 6 months