The attached test case shows an issue with how Hibernate selects the table alias to use in a subquery in an INSERT statements. For example, the HQL query
insert into TheEntity (id)
select e1.id+1 from TheEntity e1
where not exists (select 1 from TheEntity e2 where e2.id = e1.id+1)
is translated into
insert into TheEntity ( id ) select tablealias0_.id+1 as col_0_0_ from TheEntity tablealias0_ where not (exists (select 1 from TheEntity tablealias1_ where tablealias1_.id=TheEntity.id+1))
when the expected result is
insert into TheEntity ( id ) select tablealias0_.id+1 as col_0_0_ from TheEntity tablealias0_ where not (exists (select 1 from TheEntity tablealias1_ where tablealias1_.id=tablealias0_.id+1))
|