Skip to content

Commit 2312dcb

Browse files
Fabian Baumeisterbaumeister25
Fabian Baumeister
authored andcommitted
feat: Extend table inheritance article
The feedback from Hamburg was, that the single inheritance article should be more focused on the options, pros and cons of single table inheritance and define the single_table_inheritance as default and not as absolute and only correct option.
1 parent cb05349 commit 2312dcb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

modules/ROOT/pages/persistence/jpa.adoc

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ Always override the default of the relationship annotation by providing the sele
6363

6464
Mapping enums to their ordinal or name is fragile when it comes to code changes and refactoring. Define a dedicated link:https://www.baeldung.com/java-enum-values#adding-constructor[string in each enum value] for database representation. Enums then have to be treated as a custom datatype with a converter.
6565

66-
=== Use single table inheritance
66+
=== Entity inheritance
6767

68-
There are several ways to handle link:http://openjpa.apache.org/builds/1.0.4/apache-openjpa-1.0.4/docs/manual/jpa_overview_mapping_inher.html#jpa_overview_mapping_inher_tpc[inheritance in databases]. In most cases, 'single table' should be used, because it is usually the fastest way to do the mapping, as no joins are needed when retrieving, searching or persisting entities.
68+
As a good practice it is recommended to avoid entity hierarchies at all where possible and otherwise to keep the hierarchy as small as possible.
69+
If an hierarchy in the entities is needed, JPA defines several inheritance mechanisms, that are described link:https://en.wikibooks.org/wiki/Java_Persistence/Inheritance[here].
70+
In most cases, `single table` is a good choice, because it is usually the fastest way to do the mapping, as no joins are needed when retrieving, searching or persisting entities.
71+
Moreover it is rather simple and easy to understand.
72+
One major disadvantage is that the this approach can lead to huge tables with a lot of null values.
6973

7074
== Accessing the data
7175

0 commit comments

Comments
 (0)