Yeah, you are right. I switched to the entities in your blog post and just changed the inheritence type to table-per-class. This is the query I execute:
entityManager.createQuery("delete from Person where employed = :employed" )
.setParameter( "employed", false )
.executeUpdate();
The SQL statements:
Hibernate:
insert
into
HT_Person
select
person0_.id as id,
person0_.companyName as companyName
from
( select
id,
companyName,
employed,
name,
null as fellow,
0 as clazz_
from
Person
union
all select
id,
companyName,
employed,
name,
null as fellow,
1 as clazz_
from
Doctor
union
all select
id,
companyName,
employed,
name,
fellow,
2 as clazz_
from
Engineer
) person0_
where
person0_.employed=?
Hibernate:
delete
from
Person
where
(
id, companyName
) IN (
select
id,
companyName
from
HT_Person
)
Hibernate:
delete
from
Person
where
(
id, companyName
) IN (
select
id,
companyName
from
HT_Person
)
Hibernate:
delete
from
Doctor
where
(
id, companyName
) IN (
select
id,
companyName
from
HT_Person
)
Hibernate:
delete
from
Engineer
where
(
id, companyName
) IN (
select
id,
companyName
from
HT_Person
)
Hibernate:
delete
from
HT_Person
Ok, HT_Person is used, but is this meaningful?
First of all, the delete statement for the Person table seems to be executed twice.
Second, which benefit does the HT_ table provide, why not just executing this:
delete
from
Person person0_
where
person0_.employed=?
delete
from
Doctor doctor0_
where
doctor0_ .employed=?
delete
from
Engineer engineer0_
where
engineer0_.employed=?
Btw. with H2 an error occurs:
Hibernate:
create cached local temporary table if not exists HT_Person (id integer not null, companyName varchar(255) not null)
on commit drop transactional
Hibernate:
insert
into
HT_Person
select
person0_.id as id,
person0_.companyName as companyName
from
( select
id,
companyName,
employed,
name,
null as fellow,
0 as clazz_
from
Person
union
all select
id,
companyName,
employed,
name,
null as fellow,
1 as clazz_
from
Doctor
union
all select
id,
companyName,
employed,
name,
fellow,
2 as clazz_
from
Engineer
) person0_
where
person0_.employed=?
Hibernate:
delete
from
Person
where
(
id, companyName
) IN (
select
id,
companyName
from
HT_Person
)
2018-09-12 13:53:58 WARN SqlExceptionHelper:137 - SQL Error: 90052, SQLState: 90052
2018-09-12 13:53:58 ERROR SqlExceptionHelper:142 - Unterabfrage gibt mehr als eine Feld zurück
Subquery is not a single column query; SQL statement:
delete from Person where (id, companyName) IN (select id, companyName from HT_Person) [90052-176]
I just tested with Hibernate 4.3.6:
The log is all the same with the different that these entries are missing:
Hibernate:
create global temporary table HT_Doctor (id number(10,0) not null, companyName varchar2(255 char) not null)
on commit delete rows
Hibernate:
create global temporary table HT_Person (id number(10,0) not null, companyName varchar2(255 char) not null)
on commit delete rows
Hibernate:
create global temporary table HT_Engineer (id number(10,0) not null, companyName varchar2(255 char) not null)
on commit delete rows