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.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
-- strategy JOINED, Hibernate 7.4.13.Final
|
||||
|
||||
== persist 3 payments and 1 order: 7 INSERT statements
|
||||
insert into jn_payment (amount,currency,id) values (?,?,?);
|
||||
insert into jn_card_payment (card_last4,network,payment_id) values (?,?,?);
|
||||
insert into jn_payment (amount,currency,id) values (?,?,?);
|
||||
insert into jn_bank_transfer_payment (bank_code,iban,payment_id) values (?,?,?);
|
||||
insert into jn_payment (amount,currency,id) values (?,?,?);
|
||||
insert into jn_wallet_payment (provider,payment_id) values (?,?);
|
||||
insert into jn_order (payment_id,reference,id) values (?,?,?);
|
||||
|
||||
== select p from JnPayment p (polymorphic, returns 3 rows)
|
||||
select p1_0.id,case when p1_2.payment_id is not null then 1 when p1_1.payment_id is not null then 2 when p1_3.payment_id is not null then 3 end,p1_0.amount,p1_0.currency,p1_1.bank_code,p1_1.iban,p1_2.card_last4,p1_2.network,p1_3.provider
|
||||
from jn_payment p1_0
|
||||
left join jn_bank_transfer_payment p1_1 on p1_0.id=p1_1.payment_id
|
||||
left join jn_card_payment p1_2 on p1_0.id=p1_2.payment_id
|
||||
left join jn_wallet_payment p1_3 on p1_0.id=p1_3.payment_id
|
||||
order by p1_0.id;
|
||||
|
||||
== from JnCardPayment (one subclass, returns 1 row)
|
||||
select cp1_0.payment_id,cp1_1.amount,cp1_1.currency,cp1_0.card_last4,cp1_0.network
|
||||
from jn_card_payment cp1_0
|
||||
join jn_payment cp1_1 on cp1_0.payment_id=cp1_1.id;
|
||||
|
||||
== select o from JnOrder o join fetch o.payment (association to the root)
|
||||
select po1_0.id,po1_0.payment_id,p1_0.id,case when p1_2.payment_id is not null then 1 when p1_1.payment_id is not null then 2 when p1_3.payment_id is not null then 3 end,p1_0.amount,p1_0.currency,p1_1.bank_code,p1_1.iban,p1_2.card_last4,p1_2.network,p1_3.provider,po1_0.reference
|
||||
from jn_order po1_0
|
||||
join jn_payment p1_0 on p1_0.id=po1_0.payment_id
|
||||
left join jn_bank_transfer_payment p1_1 on p1_0.id=p1_1.payment_id
|
||||
left join jn_card_payment p1_2 on p1_0.id=p1_2.payment_id
|
||||
left join jn_wallet_payment p1_3 on p1_0.id=p1_3.payment_id;
|
||||
Reference in New Issue
Block a user