Advantages and Disadvantages of hierarchy mapping approach
SINGLE_TABLE
Easier to understand the
table model. Just one table is
required.
Cannot have “non null” fields.
Imagine that SmallDog has
the hairColor attribute non
null in the database. When
HugeDog get persisted an
error message from the
database will be receive, it
will inform that hairColor
cannot be null.
The entities attributes can be
found all in one table.
As general rule has a good
performance.
JOINED
Each entity will have its own
database table to store the
data.
The insert has a higher
performance cost. An insert
will be done to each database
table used in the hierarchy.
Imagine a hierarchy like C
extends B extends A, when C
is persisted 3 inserts will be
executed – one to each
mapped entity.
It will follow the OO patterns
applied in the application
code.
The join number executed in
the database queries will
increase in deeper
hierarchies.
TABLE_PER_CLASS
When the query is executed
to bring just one entity the
performance is better. A
database table will have only
one entity data.
Columns will be repeated.
The attributes found in the
abstract entities will repeated
in the concrete child entities.
When a query brings more
than one entity of the
hierarchy this query will have
a higher cost. It will be used
UNION or one query per
table.
SINGLE_TABLE
Easier to understand the
table model. Just one table is
required.
Cannot have “non null” fields.
Imagine that SmallDog has
the hairColor attribute non
null in the database. When
HugeDog get persisted an
error message from the
database will be receive, it
will inform that hairColor
cannot be null.
The entities attributes can be
found all in one table.
As general rule has a good
performance.
JOINED
Each entity will have its own
database table to store the
data.
The insert has a higher
performance cost. An insert
will be done to each database
table used in the hierarchy.
Imagine a hierarchy like C
extends B extends A, when C
is persisted 3 inserts will be
executed – one to each
mapped entity.
It will follow the OO patterns
applied in the application
code.
The join number executed in
the database queries will
increase in deeper
hierarchies.
TABLE_PER_CLASS
When the query is executed
to bring just one entity the
performance is better. A
database table will have only
one entity data.
Columns will be repeated.
The attributes found in the
abstract entities will repeated
in the concrete child entities.
When a query brings more
than one entity of the
hierarchy this query will have
a higher cost. It will be used
UNION or one query per
table.
No comments:
Post a Comment