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:
2026-10-24 10:02:28 +00:00
parent 833f3e1c31
commit 807f681ed1
44 changed files with 1533 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
Hibernate 7.4.13.Final, H2 in memory
== SINGLE_TABLE
INSERT statements to save 3 payments + 1 order: 4
tables and row counts:
st_order = 1
st_payment = 3
IS_NULLABLE for card_last4 in st_payment: YES
foreign keys on st_order: 1
discriminator values stored: [BANK, CARD, WALLET]
raw INSERT of a CARD row with no card_last4: Check constraint violation: "ST_PAYMENT_SUBCLASS_COLUMNS: "; SQL statement:
insert into st_payment (id, amount, currency, payment_type) values (900, 1.00, 'EUR', 'CARD') [23513-240]
== JOINED
INSERT statements to save 3 payments + 1 order: 7
tables and row counts:
jn_bank_transfer_payment = 1
jn_card_payment = 1
jn_order = 1
jn_payment = 3
jn_wallet_payment = 1
IS_NULLABLE for card_last4 in jn_card_payment: NO
foreign keys on jn_order: 1
== TABLE_PER_CLASS
INSERT statements to save 3 payments + 1 order: 4
tables and row counts:
tp_bank_transfer_payment = 1
tp_card_payment = 1
tp_order = 1
tp_wallet_payment = 1
IS_NULLABLE for card_last4 in tp_card_payment: NO
foreign keys on tp_order: 0
== SINGLE_TABLE with nullable = false on subclass columns
IS_NULLABLE: [A_VALUE | NO, B_VALUE | NO, ID | NO, KIND | NO]
persist(new SnA()): org.hibernate.exception.ConstraintViolationException: could not execute statement [NULL not allowed for column "B_VALUE"; SQL statement:
insert into sn_root (a_value,kind,id) values (?,'A',?) [23502-240]] [insert into sn_root (a_value,kind,id) values (?,'A',?)]
== TABLE_PER_CLASS with GenerationType.IDENTITY
org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: com.ankurm.inheritance.TpcIdentityCard
== querying a @MappedSuperclass
tables: [mp_invoice, mp_receipt]
org.hibernate.query.sqm.UnknownEntityException: Could not resolve root entity 'AuditedBase'