Kai Zander (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-15517 (
https://hibernate.atlassian.net/browse/HHH-15517?atlOrigin=eyJpIjoiYWJlMj...
)
Re: "insert from select" With hibernate.default_schema Configured Doesn't
Work With Hibernate 6 (
https://hibernate.atlassian.net/browse/HHH-15517?atlOrigin=eyJpIjoiYWJlMj...
)
I experimented a bit more and found the following:
If I rewrite the HQL to this (don’t select id , use distinct instead of group by ):
insert into TabData (col1, col2, col3)
select distinct col1, col2, col3
from TabDataStaging
Hibernate 6 does the following:
insert into HTE_tab_data(col1, col2, col3, rn_)
( select distinct p2_0.col1,
p2_0.col2,
p2_0.col3,
row_number () over () -- adding this column effectively disables the `
distinct `
from tab_data_staging p2_0);
Followed by the updates on the HTE table you were suspecting earlier:
update HTE_tab_data set id=? where rn_=?
update HTE_tab_data set id=? where rn_=?
...
Followed by
insert into tab_data(col1,col2,col3,id)
select p1_0.col1,p1_0.col2,p1_0.col3,p1_0.id
from HTE_tab_data p1_0
The final insert into tab_data can then fail due to unique constraint violation (I have a
composite unique constraint on col1, col2, col3 ), because even though I’m using distinct
, the row_number() clause added by Hibernate effectively disabled it…
(
https://hibernate.atlassian.net/browse/HHH-15517#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15517#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:7afd384 )