Well, if you read the βInheritanceβ chapter of the Hibernate documentation a little further :-) you will see that the above example for mixing tables into one hierarchy and strategies of a subclass table is actually nothing more than a table for a hierarchy with the addition of secondary tables:
<class name="Payment" table="PAYMENT"> <id name="id" type="long" column="PAYMENT_ID"> <generator class="native"/> </id> <discriminator column="PAYMENT_TYPE" type="string"/> <property name="amount" column="AMOUNT"/> ... <subclass name="CreditCardPayment" discriminator-value="CREDIT"> <join table="CREDIT_PAYMENT"> <property name="creditCardType" column="CCTYPE"/> ... </join> </subclass> <subclass name="CashPayment" discriminator-value="CASH"> ... </subclass> </class>
You can do the same using @SecondaryTable annotation :
@Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="PAYMENT_TYPE") @DiscriminatorValue("PAYMENT") public class Payment { ... } @Entity @DiscriminatorValue("CREDIT") @SecondaryTable(name="CREDIT_PAYMENT", pkJoinColumns={ @PrimaryKeyJoinColumn(name="payment_id", referencedColumnName="id") ) public class CreditCardPayment extends Payment { ... } @Entity @DiscriminatorValue("CASH") public class CashPayment extends Payment { ... }
source share