Reputation: 2224
I was going through the JPA specification on available strategies to map an inheritance relationship to the relational model. I didn't quiet understand the following statements in the spec:
The Single Table per Class Hierarchy Strategy:
"This strategy provides good support for polymorphic relationships between entities and queries that cover the entire entity class hierarchy"
The Table per Concrete Class Strategy:
"This strategy provides poor support for polymorphic relationships"
Can anyone further clarify the meaning of these statements on how polymorphism is affected by these strategies?
Upvotes: 2
Views: 1305
Reputation: 5131
Single Table per Class Hierarchy
this strategy provides a good polymorphic relationships between entity and query is because that JPA can predict what entity is the query for by its DiscriminatorValue
. example, let say you have an entity like this.
select a, b, c, type from table_c;
and by using JPA, you can get class A or class B even though you're using table_c and it also easier for you to create a new entity by just adding a new column into that table. (this is what people usually mean by Denormalisation
)
Table per Concrete Class
this strategy provides a poor support for polymorphic relationships is because one table is only for one class. which mean that if you need to create a new entity, then you should create a new table.
Upvotes: 0
Reputation: 13556
Consider we have a domain model as below
Please study the links provided below.
Table per concrete class - Again, data is stored in multiple tables hence
Table per concrete class exmaple
It all depends on your requirement. If you have ample database and need performance, Single table strategy is the way to go. If you have database constraint, then other strategies are to be followed.
Upvotes: 4
Reputation: 954
Conside below example.The Table per Concrete Class Strategy
Here each concrete class is mapped as normal persistent class. so we have 3 tables; PERSON, EMPLOYEE and OWNER to persist the class data. In this the mapping of the subclass repeats the properties of the parent class.
Here you have few disadvantages :
Upvotes: 2
Reputation: 11531
See this page, which has examples of each http://www.datanucleus.org/products/accessplatform_4_1/jpa/orm/inheritance.html
Upvotes: 0