Table per class hierarchy by R4R Team

Suppose we have an interface Payment with the implementors CreditCardPayment, CashPayment, and ChequePayment

The table per hierarchy mapping would display in the following way:

<class name="Payment" table="PAYMENT">
    <id name="id" type="long" column="PAYMENT_ID">
        <generator class="native"/>
    <discriminator column="PAYMENT_TYPE" type="string"/>
    <property name="amount" column="AMOUNT"/>
    <subclass name="CreditCardPayment" discriminator-value="CREDIT">
        <property name="creditCardType" column="CCTYPE"/>
    <subclass name="CashPayment" discriminator-value="CASH">
    <subclass name="ChequePayment" discriminator-value="CHEQUE">

There is a limitation of this mapping strategy: columns declared by the subclasses, such as CCTYPE, cannot have NOT NULL constraints. Exactly one table is required. 
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!