1. Table per concrete class with implicit polymorphism
We create an abstract superclass and we map it as @MappedSuperclass. The concrete classes extend this abstract class and this way we achieve an implicit polymorphism. In the database, the two classes are two different tables with no actual relation between them.
2. Table with concrete class with unions
The superclass is mapped as a proper entity and we use @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS). The concrete implementation classes extend this superclass but again they are two separate tables with no relation between them on database table. On Java code though, they can share code.
3. Table per class hierarchy
The inheritance strategy is SINGLE_TABLE and both concrete classes are mapped on a single table in the database. The problem with this implementation is that this table may have many nullable columns. Each of them also needs a @DiscriminatorColumn to distinguish between the different classes mapped in the table.
4. Table per subclass with joins
The superclass and the subclasses have a table representation on the database. The primary key of the superclass is also the foreign key to the subclasses. The inheritance type is JOINED and no discriminators are used for this implementation.
We create an abstract superclass and we map it as @MappedSuperclass. The concrete classes extend this abstract class and this way we achieve an implicit polymorphism. In the database, the two classes are two different tables with no actual relation between them.
2. Table with concrete class with unions
The superclass is mapped as a proper entity and we use @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS). The concrete implementation classes extend this superclass but again they are two separate tables with no relation between them on database table. On Java code though, they can share code.
3. Table per class hierarchy
The inheritance strategy is SINGLE_TABLE and both concrete classes are mapped on a single table in the database. The problem with this implementation is that this table may have many nullable columns. Each of them also needs a @DiscriminatorColumn to distinguish between the different classes mapped in the table.
4. Table per subclass with joins
The superclass and the subclasses have a table representation on the database. The primary key of the superclass is also the foreign key to the subclasses. The inheritance type is JOINED and no discriminators are used for this implementation.
Comments
Post a Comment