Table Per Concrete Class


Table Per Concrete Class

A table is established for each concrete class in the inheritance hierarchy in the Table Per Concrete Class technique to hold all of the characteristics of that class and all of its superclasses. Several ORM systems (e.g., JPA) make this technique optional, and accessing root or branch classes might be difficult and wasteful.

The parent class must use the @Inheritance(strategy = InheritanceType.TABLE PER CLASS) annotation, while the subclasses must use the @AttributeOverrides annotation.
Table per concrete class strategy is specified by @Inheritance(strategy = InheritanceType.TABLE PER CLASS). Only the parent class should include this information.

@AttributeOverrides specifies that the attributes of the parent class will be overridden in this class. Columns from the parent class table will be added to the subclass table in the table structure.

Payment, Card, and Cheque are the three classes in our sample hierarchy. Card and Cheque classes are considered concrete classes in this case. Because they are full-fledged classes (We can create these objects and make use of them), on the other hand, payment is not regarded as a concrete class because it does not exist without a Card or a Cheque.

CREATE TABLE `card_table` (
`payid` INT(11) NULL DEFAULT NULL,
`amount` DOUBLE NULL DEFAULT NULL,
`paydate` DATE NULL DEFAULT NULL,
`cardnumber` INT(11) NULL DEFAULT NULL,
`cardtype` VARCHAR(50) NULL DEFAULT NULL
)

COLLATE=’latin1_swedish_ci’
CREATE TABLE cheque table ( payid INT(11) NULL DEFAULT NULL, amount INT(11) NULL DEFAULT NULL, paydate DATE NULL DEFAULT NULL, chqnumber INT(11) NULL DEFAULT NULL, chqtype VARCHAR(50) NULL DEFAULT NULL, chqtype VARCHAR(50) NULL DEFAULT NULL )
COLLATE=’latin1 swedish ci’\sENGINE=InnoDB;\s[/sql]