Files
hibernate-demo/inheritance/output/02-sql-single-table.txt
T
asmhatre 807f681ed1 Add inheritance module: SINGLE_TABLE vs JOINED vs TABLE_PER_CLASS on Hibernate 7.4.13.Final
Same payment hierarchy mapped three ways plus @MappedSuperclass, run with plain Hibernate on H2.
Tests assert and write the generated DDL, the INSERT/SELECT SQL, row/insert/FK/nullability counts and
the three failures (NOT NULL on a SINGLE_TABLE subclass column, IDENTITY with TABLE_PER_CLASS, querying a
@MappedSuperclass); Bench writes indicative polymorphic-query timings. No docs folder: depth lives in the post.
2026-10-24 10:02:28 +00:00

23 lines
1.2 KiB
Plaintext

-- strategy SINGLE_TABLE, Hibernate 7.4.13.Final
== persist 3 payments and 1 order: 4 INSERT statements
insert into st_payment (amount,currency,card_last4,network,payment_type,id) values (?,?,?,?,'CARD',?);
insert into st_payment (amount,currency,bank_code,iban,payment_type,id) values (?,?,?,?,'BANK',?);
insert into st_payment (amount,currency,provider,payment_type,id) values (?,?,?,'WALLET',?);
insert into st_order (payment_id,reference,id) values (?,?,?);
== select p from StPayment p (polymorphic, returns 3 rows)
select p1_0.id,p1_0.payment_type,p1_0.amount,p1_0.currency,p1_0.bank_code,p1_0.iban,p1_0.card_last4,p1_0.network,p1_0.provider
from st_payment p1_0
order by p1_0.id;
== from StCardPayment (one subclass, returns 1 row)
select cp1_0.id,cp1_0.amount,cp1_0.currency,cp1_0.card_last4,cp1_0.network
from st_payment cp1_0
where cp1_0.payment_type='CARD';
== select o from StOrder o join fetch o.payment (association to the root)
select po1_0.id,po1_0.payment_id,p1_0.id,p1_0.payment_type,p1_0.amount,p1_0.currency,p1_0.bank_code,p1_0.iban,p1_0.card_last4,p1_0.network,p1_0.provider,po1_0.reference
from st_order po1_0
join st_payment p1_0 on p1_0.id=po1_0.payment_id;