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 () 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
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… |