Implicit polymorphism lets Hibernate answer polymorphic queries without an explicit mapped inheritance hierarchy. It can query a persistent interface and combine results from every mapped class that implements it. section 7.7
A table-per-concrete-class mapping applies the behavior through several coordinated choices:
- Map each concrete class with @Entity; each class receives an independent table containing its own and inherited columns. section 7.1
- Annotate the shared superclass with @MappedSuperclass, because superclass properties are otherwise ignored and remain nonpersistent. section 7.1
- Override inherited column mappings with @AttributeOverride when concrete tables require different names, such as CC_OWNER. section 7.1
- Share repository behavior through a generic @NoRepositoryBean base interface while exposing concrete repositories for each entity type. section 7.1
Billing details and electronic payment options
CreditCard and BankAccount can extend BillingDetails while persisting to separate CREDITCARD and BANKACCOUNT tables. A shared BillingDetailsRepository<T extends BillingDetails, ID> supplies findByOwner, and concrete repositories add findByExpYear or findBySwift. Separately, Hibernate can execute select o from ElectronicPaymentOption o even when implementing classes come from different persistent hierarchies. section 7.1 section 7.7
Use the mapping diagram to compare the independent-table layout for concrete classes. section 7.1
