• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Entity Inheritance Strategies

 
sai rama krishna
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am reading about EJB3 and entity beans.

Entity Inheritance Strategies are 3 types
1.Single table Strategy
2. Table per class Strategy –
3.Join Strategy

Out of these 3 strategies which one is most commonly used and which one is better to use in which case. Table per concrete class may be lot of overhead on database right as we are storing base class data again in the subclass tables?
please advise.
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to understand this is to try to implement it. Then you will see how your entities are mapped to database tables.

Try to code such scenario:






Next try three inheritance strategies between Parent and Child. Take note of what hibernate retrieves in parents set. Is there proxy of Child or proxy of Parent?
 
Richard Chesterwood
Virtual Pair Programmers Rep
Greenhorn
Posts: 29
7
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definitely try it for yourself, but in the course we summarize as follows:

1) Single table is the best performer if you have lots of polymorphic queries in your code, and also if you're selecting specific object types. BUT, it's a bad mapping to a database, it's not a good schema, you need lots of NULLs and constraints are difficult/impossible (eg you can't set NOT NULL Columns)

2) Joined Table has a much better, more natural database schema, but it won't perform so well when querying. Whether you are selecting the whole hierarchy (ie a polymorphic query) or a single object type, a JOIN will be needed.

3) Table per concrete class is the weakest (in our opinion) in that it's not a great database schema (but not bad) and for polymorphic queries expensive UNIONs are needed. But it's "pro" is that if you're just selecting a specific concrete type, this is good performance (a single select needed on the specific table). I think this is the least useful strategy, and I think it isn't even mandated by JPA.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic