SlideShare a Scribd company logo
Professional Open Source™




           Mapping Inheritance




© JBoss, Inc. 2003, 2004.                         07/17/04   1
Mapping Class Inheritance
                                                                     Professional Open Source™


  Inheritance is such a visible structural mismatch between the object-
   oriented and relational worlds because object-oriented systems
   model both is a and has a relationships.
  SQL-based models provide only has a relationships between entities;
  SQL database management systems don’t support type inheritance .

  Four different approaches to representing an inheritance hierarchy:
           – Table per concrete class with implicit polymorphism—Use no explicit
             inheritance mapping, and default runtime polymorphic behavior.
           – Table per concrete class—Discard polymorphism and inheritance
             relationships completely from the SQL schema.
           – Table per class hierarchy—Enable polymorphism by denormalizing the
             SQL schema, and utilize a type discriminator column that holds type
             information.
           – Table per subclass—Represent is a (inheritance) relationships as has a
             (foreign key) relationships.


© JBoss, Inc. 2003, 2004.                                                                        2
Table per concrete class with implicit polymorphism
                                                                          Professional Open Source™


  The mapping for CreditCard and BankAccount is straightforward, each in its
  own entity <class> element, as we have done already for classes without a superclass
  (or persistent interfaces).


  Hibernate still knows about the superclass (or any interface) because it scans the
   persistent classes on startup.




© JBoss, Inc. 2003, 2004.                                                                             3
Problems with previous strategy
                                                             Professional Open Source™


  The main problem with this approach is that it doesn’t support
   polymorphic associations very well. In the database, associations are
   usually represented as foreign key relationships. As both the
   subclasses has different table which has a different foreign key, if we
   have to use superclass reference in any other class, it is difficult.

  In previous figure, if the subclasses are all mapped to different
  tables, a polymorphic association to their superclass (abstract
   BillingDetails in this example) can’t be represented as a simple
   foreign key relationship

  Polymorphic queries (queries that return objects of all classes that
   match the interface of the queried class) are also problematic.
  A query against the superclass must be executed as several SQL
   SELECTs, one for each concrete subclass.


© JBoss, Inc. 2003, 2004.                                                                4
Problems with previous strategy
                                                        Professional Open Source™



A further conceptual problem with this mapping strategy is that
several different columns, of different tables, share exactly the
same semantics. This makes schema evolution more complex.

 For example, a change to a superclass property results in changes
to multiple columns. It also makes it much more difficult to
implement database integrity constraints that apply to all
subclasses.

This approach is recommended where polymorphism isn’t usually
required, and when modification of the superclass in the future is
unlikely.



© JBoss, Inc. 2003, 2004.                                                           5
Table per concrete class with unions
                                                            Professional Open Source™


  In this situation, we again have two tables and duplicate superclass
   columns in both: CREDIT_CARD and BANK_ACCOUNT.




© JBoss, Inc. 2003, 2004.                                                               6
Advantages of this strategy
                                                            Professional Open Source™


  The first advantage you may notice with this strategy is the shared
   declaration of superclass (or interface) properties. No longer do you
   have to duplicate these mappings for all concrete classes—Hibernate
   takes care of this.

  Keep in mind that the SQL schema still isn’t aware of the inheritance;
   effectively, we’ve mapped two unrelated tables to a more expressive
   class structure.
  Polymorphic queries use union

  Another much more important advantage is the ability to handle
   polymorphic associations; for example, an association mapping
   from User to BillingDetails would now be possible. Hibernate can use
   a UNION query to simulate a single table as the target of the
   association mapping


© JBoss, Inc. 2003, 2004.                                                               7
Table per class hierarchy
                                                              Professional Open Source™


  An entire class hierarchy can be mapped to a single table. This table
   includes columns for all properties of all classes in the hierarchy. The
   concrete subclass represented by a particular row is identified by the
   value of a type discriminator column.




© JBoss, Inc. 2003, 2004.                                                                 8
Advantages of table per class hierarchy strategy
                                                          Professional Open Source™


  This mapping strategy is a winner in terms of both performance and
   simplicity.
  It’s the best-performing way to represent polymorphism—both
   polymorphic and non polymorphic queries perform well—and it’s even
   easy to implement by hand.
  Ad-hoc reporting is possible without complex joins or unions. Schema
   evolution is straightforward.

  There is one major problem: Columns for properties declared by
   subclasses must be declared to be nullable. If your subclasses each
   define several non nullable properties, the loss of NOT NULL
   constraints may be a serious problem from the point of view of data
   integrity.
  Another important issue is normalization.



© JBoss, Inc. 2003, 2004.                                                             9
Table per subclass
                                                              Professional Open Source™


  The fourth option is to represent inheritance relationships as relational
   foreign key associations.

  Every class/subclass that declares persistent properties—including
  abstract classes and even interfaces—has its own table.

  Unlike the table per concrete class strategy we mapped first, the table
   here contains columns only for each non inherited property (each
   property declared by the subclass itself) along with a primary key that
   is also a foreign key of the superclass table.

  See next page for diagram ..




© JBoss, Inc. 2003, 2004.                                                                 10
Mapping all classes of the hierarchy to their own table
                                                                 Professional Open Source™




© JBoss, Inc. 2003, 2004.                                                                    11
Professional Open Source™


  If an instance of the CreditCard subclass is made persistent, the
   values of properties declared by the BillingDetails superclass are
   persisted to a new row of the BILLING_DETAILS table. Only the
   values of properties declared by the subclass are persisted to a new
   row of the CREDIT_CARD table. The two rows are linked together
  by their shared primary key value. Later, the subclass instance may
   be retrieved from the database by joining the subclass table with the
   superclass table.

  The primary advantage of this strategy is that the SQL schema is
   normalized. Schema evolution and integrity constraint definition are
   straightforward.

  A polymorphic association to a particular subclass may be
   represented as a foreign key referencing the table of that particular
   subclass.

© JBoss, Inc. 2003, 2004.                                                                12
Choosing a strategy
                                                                   Professional Open Source™


  If you don’t require polymorphic associations or queries, lean toward table per
   concrete-class—in other words, if you never or rarely query for BillingDetails
   and you have no class that has an association to BillingDetails(our model
   has).

  An explicit UNION-based mapping should be preferred, because (optimized)
   polymorphic queries and associations will then be possible later. Implicit
   polymorphism is mostly useful for queries utilizing non-persistence-related
   interfaces.

  If you do require polymorphic associations (an association to a superclass,
   hence to all classes in the hierarchy with dynamic resolution of the concrete
   class at runtime) or queries, and subclasses declare relatively few properties
   (particularly if the main difference between subclasses is in their behavior),
   lean toward table-per-class-hierarchy. Your goal is to minimize the number of
   nullable columns and to convince yourself (and your DBA) that a
   denormalized schema won’t create problems in the long run.


© JBoss, Inc. 2003, 2004.                                                                      13
Professional Open Source™


  If you do require polymorphic associations or queries, and subclasses
  declare many properties (subclasses differ mainly by the data they
   hold), lean toward table-per-subclass. Or, depending on the width and
   depth of your inheritance hierarchy and the possible cost of joins
   versus unions, use table-per-concrete-class.




© JBoss, Inc. 2003, 2004.                                                             14

More Related Content

What's hot

Ch 12 O O D B Dvlpt
Ch 12  O O  D B  DvlptCh 12  O O  D B  Dvlpt
Ch 12 O O D B Dvlpt
guest8fdbdd
 
Cb32924927
Cb32924927Cb32924927
Cb32924927
IJMER
 
uml reference package_diagram
uml reference package_diagramuml reference package_diagram
uml reference package_diagram
Mohamed Zakarya Abdelgawad
 
21792 relational database managementsystem
21792 relational database managementsystem21792 relational database managementsystem
21792 relational database managementsystem
Universitas Bina Darma Palembang
 
Form part1
Form part1Form part1
Form part1
Sanjeev Pandey
 
Oop09 6
Oop09 6Oop09 6
Oop09 6
schwaa
 
Unified Modeling Language
Unified Modeling LanguageUnified Modeling Language
Unified Modeling Language
Khushboo Wadhwani
 
Case Study Uml
Case Study UmlCase Study Uml
Case Study Uml
ganesh12july
 
UML Modeling in Java
UML Modeling in JavaUML Modeling in Java
UML Modeling in Java
Daffodil International University
 

What's hot (9)

Ch 12 O O D B Dvlpt
Ch 12  O O  D B  DvlptCh 12  O O  D B  Dvlpt
Ch 12 O O D B Dvlpt
 
Cb32924927
Cb32924927Cb32924927
Cb32924927
 
uml reference package_diagram
uml reference package_diagramuml reference package_diagram
uml reference package_diagram
 
21792 relational database managementsystem
21792 relational database managementsystem21792 relational database managementsystem
21792 relational database managementsystem
 
Form part1
Form part1Form part1
Form part1
 
Oop09 6
Oop09 6Oop09 6
Oop09 6
 
Unified Modeling Language
Unified Modeling LanguageUnified Modeling Language
Unified Modeling Language
 
Case Study Uml
Case Study UmlCase Study Uml
Case Study Uml
 
UML Modeling in Java
UML Modeling in JavaUML Modeling in Java
UML Modeling in Java
 

Viewers also liked

Wonderful World Of Mysql Storage Engines Hl2008 Rus
Wonderful World Of Mysql Storage Engines Hl2008 RusWonderful World Of Mysql Storage Engines Hl2008 Rus
Wonderful World Of Mysql Storage Engines Hl2008 RusOntico
 
15 jpa introduction
15 jpa introduction15 jpa introduction
15 jpa introduction
thirumuru2012
 
Ch09
Ch09Ch09
Ch09
蕭美蓮
 
15 jpa
15 jpa15 jpa
Database design
Database designDatabase design
Database design
FLYMAN TECHNOLOGY LIMITED
 
Inheritance
InheritanceInheritance
Inheritance
ankush_kumar
 
Class method
Class methodClass method
Class method
kamal kotecha
 

Viewers also liked (7)

Wonderful World Of Mysql Storage Engines Hl2008 Rus
Wonderful World Of Mysql Storage Engines Hl2008 RusWonderful World Of Mysql Storage Engines Hl2008 Rus
Wonderful World Of Mysql Storage Engines Hl2008 Rus
 
15 jpa introduction
15 jpa introduction15 jpa introduction
15 jpa introduction
 
Ch09
Ch09Ch09
Ch09
 
15 jpa
15 jpa15 jpa
15 jpa
 
Database design
Database designDatabase design
Database design
 
Inheritance
InheritanceInheritance
Inheritance
 
Class method
Class methodClass method
Class method
 

Similar to 05 inheritance

01 persistence and domain modeling
01 persistence and domain modeling01 persistence and domain modeling
01 persistence and domain modeling
thirumuru2012
 
06 association of value types
06 association of value types06 association of value types
06 association of value types
thirumuru2012
 
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapOverview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Vikas Jagtap
 
Rbce
Rbce Rbce
Specialization and Generalization_lec_13.pptx
Specialization and Generalization_lec_13.pptxSpecialization and Generalization_lec_13.pptx
Specialization and Generalization_lec_13.pptx
kallarkahar47
 
Template pattern
Template patternTemplate pattern
Template pattern
Vithushan Vinayagamoorthy
 
Inheritance
InheritanceInheritance
Inheritance
InheritanceInheritance
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Uml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot netUml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot net
mekhap
 
Database System Modeling Union_lec_14.pptx
Database System Modeling Union_lec_14.pptxDatabase System Modeling Union_lec_14.pptx
Database System Modeling Union_lec_14.pptx
kallarkahar47
 
11 transitive persistence and filters
11 transitive persistence and filters11 transitive persistence and filters
11 transitive persistence and filters
thirumuru2012
 
Micro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeMicro Anti-patterns in Java Code
Micro Anti-patterns in Java Code
Ganesh Samarthyam
 
Oop
OopOop
Software Testing and UML Lab
Software Testing and UML LabSoftware Testing and UML Lab
Software Testing and UML Lab
Harsh Kishore Mishra
 
Data Base Design.pptx
Data Base Design.pptxData Base Design.pptx
Data Base Design.pptx
SunilMS21
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
cesarmendez78
 
Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
Ivan Paredes
 
Top 30 Technical interview questions
Top 30 Technical interview questionsTop 30 Technical interview questions
Top 30 Technical interview questions
SohailSaifi15
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Meenakshi Devi
 

Similar to 05 inheritance (20)

01 persistence and domain modeling
01 persistence and domain modeling01 persistence and domain modeling
01 persistence and domain modeling
 
06 association of value types
06 association of value types06 association of value types
06 association of value types
 
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapOverview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
 
Rbce
Rbce Rbce
Rbce
 
Specialization and Generalization_lec_13.pptx
Specialization and Generalization_lec_13.pptxSpecialization and Generalization_lec_13.pptx
Specialization and Generalization_lec_13.pptx
 
Template pattern
Template patternTemplate pattern
Template pattern
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
 
Uml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot netUml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot net
 
Database System Modeling Union_lec_14.pptx
Database System Modeling Union_lec_14.pptxDatabase System Modeling Union_lec_14.pptx
Database System Modeling Union_lec_14.pptx
 
11 transitive persistence and filters
11 transitive persistence and filters11 transitive persistence and filters
11 transitive persistence and filters
 
Micro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeMicro Anti-patterns in Java Code
Micro Anti-patterns in Java Code
 
Oop
OopOop
Oop
 
Software Testing and UML Lab
Software Testing and UML LabSoftware Testing and UML Lab
Software Testing and UML Lab
 
Data Base Design.pptx
Data Base Design.pptxData Base Design.pptx
Data Base Design.pptx
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
 
Top 30 Technical interview questions
Top 30 Technical interview questionsTop 30 Technical interview questions
Top 30 Technical interview questions
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
 

More from thirumuru2012

14 hql
14 hql14 hql
14 criteria api
14 criteria api14 criteria api
14 criteria api
thirumuru2012
 
13 caching latest
13 caching   latest13 caching   latest
13 caching latest
thirumuru2012
 
12 hibernate int&cache
12  hibernate int&cache12  hibernate int&cache
12 hibernate int&cache
thirumuru2012
 
12 global fetching strategies
12 global fetching strategies12 global fetching strategies
12 global fetching strategies
thirumuru2012
 
10 conversations new
10 conversations new10 conversations new
10 conversations new
thirumuru2012
 
09 transactions new1
09 transactions new109 transactions new1
09 transactions new1
thirumuru2012
 
09 transactions new
09 transactions new09 transactions new
09 transactions new
thirumuru2012
 
07 association of entities
07 association of entities07 association of entities
07 association of entities
thirumuru2012
 
04 dataaccess
04 dataaccess04 dataaccess
04 dataaccess
thirumuru2012
 
02 hibernateintroduction
02 hibernateintroduction02 hibernateintroduction
02 hibernateintroduction
thirumuru2012
 
15 jpaql
15 jpaql15 jpaql
15 jpaql
thirumuru2012
 

More from thirumuru2012 (12)

14 hql
14 hql14 hql
14 hql
 
14 criteria api
14 criteria api14 criteria api
14 criteria api
 
13 caching latest
13 caching   latest13 caching   latest
13 caching latest
 
12 hibernate int&cache
12  hibernate int&cache12  hibernate int&cache
12 hibernate int&cache
 
12 global fetching strategies
12 global fetching strategies12 global fetching strategies
12 global fetching strategies
 
10 conversations new
10 conversations new10 conversations new
10 conversations new
 
09 transactions new1
09 transactions new109 transactions new1
09 transactions new1
 
09 transactions new
09 transactions new09 transactions new
09 transactions new
 
07 association of entities
07 association of entities07 association of entities
07 association of entities
 
04 dataaccess
04 dataaccess04 dataaccess
04 dataaccess
 
02 hibernateintroduction
02 hibernateintroduction02 hibernateintroduction
02 hibernateintroduction
 
15 jpaql
15 jpaql15 jpaql
15 jpaql
 

Recently uploaded

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 

Recently uploaded (20)

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 

05 inheritance

  • 1. Professional Open Source™ Mapping Inheritance © JBoss, Inc. 2003, 2004. 07/17/04 1
  • 2. Mapping Class Inheritance Professional Open Source™  Inheritance is such a visible structural mismatch between the object- oriented and relational worlds because object-oriented systems model both is a and has a relationships.  SQL-based models provide only has a relationships between entities;  SQL database management systems don’t support type inheritance .  Four different approaches to representing an inheritance hierarchy: – Table per concrete class with implicit polymorphism—Use no explicit inheritance mapping, and default runtime polymorphic behavior. – Table per concrete class—Discard polymorphism and inheritance relationships completely from the SQL schema. – Table per class hierarchy—Enable polymorphism by denormalizing the SQL schema, and utilize a type discriminator column that holds type information. – Table per subclass—Represent is a (inheritance) relationships as has a (foreign key) relationships. © JBoss, Inc. 2003, 2004. 2
  • 3. Table per concrete class with implicit polymorphism Professional Open Source™  The mapping for CreditCard and BankAccount is straightforward, each in its  own entity <class> element, as we have done already for classes without a superclass  (or persistent interfaces).  Hibernate still knows about the superclass (or any interface) because it scans the persistent classes on startup. © JBoss, Inc. 2003, 2004. 3
  • 4. Problems with previous strategy Professional Open Source™  The main problem with this approach is that it doesn’t support polymorphic associations very well. In the database, associations are usually represented as foreign key relationships. As both the subclasses has different table which has a different foreign key, if we have to use superclass reference in any other class, it is difficult.  In previous figure, if the subclasses are all mapped to different  tables, a polymorphic association to their superclass (abstract BillingDetails in this example) can’t be represented as a simple foreign key relationship  Polymorphic queries (queries that return objects of all classes that match the interface of the queried class) are also problematic.  A query against the superclass must be executed as several SQL SELECTs, one for each concrete subclass. © JBoss, Inc. 2003, 2004. 4
  • 5. Problems with previous strategy Professional Open Source™ A further conceptual problem with this mapping strategy is that several different columns, of different tables, share exactly the same semantics. This makes schema evolution more complex. For example, a change to a superclass property results in changes to multiple columns. It also makes it much more difficult to implement database integrity constraints that apply to all subclasses. This approach is recommended where polymorphism isn’t usually required, and when modification of the superclass in the future is unlikely. © JBoss, Inc. 2003, 2004. 5
  • 6. Table per concrete class with unions Professional Open Source™  In this situation, we again have two tables and duplicate superclass columns in both: CREDIT_CARD and BANK_ACCOUNT. © JBoss, Inc. 2003, 2004. 6
  • 7. Advantages of this strategy Professional Open Source™  The first advantage you may notice with this strategy is the shared declaration of superclass (or interface) properties. No longer do you have to duplicate these mappings for all concrete classes—Hibernate takes care of this.  Keep in mind that the SQL schema still isn’t aware of the inheritance; effectively, we’ve mapped two unrelated tables to a more expressive class structure.  Polymorphic queries use union  Another much more important advantage is the ability to handle polymorphic associations; for example, an association mapping from User to BillingDetails would now be possible. Hibernate can use a UNION query to simulate a single table as the target of the association mapping © JBoss, Inc. 2003, 2004. 7
  • 8. Table per class hierarchy Professional Open Source™  An entire class hierarchy can be mapped to a single table. This table includes columns for all properties of all classes in the hierarchy. The concrete subclass represented by a particular row is identified by the value of a type discriminator column. © JBoss, Inc. 2003, 2004. 8
  • 9. Advantages of table per class hierarchy strategy Professional Open Source™  This mapping strategy is a winner in terms of both performance and simplicity.  It’s the best-performing way to represent polymorphism—both polymorphic and non polymorphic queries perform well—and it’s even easy to implement by hand.  Ad-hoc reporting is possible without complex joins or unions. Schema evolution is straightforward.  There is one major problem: Columns for properties declared by subclasses must be declared to be nullable. If your subclasses each define several non nullable properties, the loss of NOT NULL constraints may be a serious problem from the point of view of data integrity.  Another important issue is normalization. © JBoss, Inc. 2003, 2004. 9
  • 10. Table per subclass Professional Open Source™  The fourth option is to represent inheritance relationships as relational foreign key associations.  Every class/subclass that declares persistent properties—including  abstract classes and even interfaces—has its own table.  Unlike the table per concrete class strategy we mapped first, the table here contains columns only for each non inherited property (each property declared by the subclass itself) along with a primary key that is also a foreign key of the superclass table.  See next page for diagram .. © JBoss, Inc. 2003, 2004. 10
  • 11. Mapping all classes of the hierarchy to their own table Professional Open Source™ © JBoss, Inc. 2003, 2004. 11
  • 12. Professional Open Source™  If an instance of the CreditCard subclass is made persistent, the values of properties declared by the BillingDetails superclass are persisted to a new row of the BILLING_DETAILS table. Only the values of properties declared by the subclass are persisted to a new row of the CREDIT_CARD table. The two rows are linked together  by their shared primary key value. Later, the subclass instance may be retrieved from the database by joining the subclass table with the superclass table.  The primary advantage of this strategy is that the SQL schema is normalized. Schema evolution and integrity constraint definition are straightforward.  A polymorphic association to a particular subclass may be represented as a foreign key referencing the table of that particular subclass. © JBoss, Inc. 2003, 2004. 12
  • 13. Choosing a strategy Professional Open Source™  If you don’t require polymorphic associations or queries, lean toward table per concrete-class—in other words, if you never or rarely query for BillingDetails and you have no class that has an association to BillingDetails(our model has).  An explicit UNION-based mapping should be preferred, because (optimized) polymorphic queries and associations will then be possible later. Implicit polymorphism is mostly useful for queries utilizing non-persistence-related interfaces.  If you do require polymorphic associations (an association to a superclass, hence to all classes in the hierarchy with dynamic resolution of the concrete class at runtime) or queries, and subclasses declare relatively few properties (particularly if the main difference between subclasses is in their behavior), lean toward table-per-class-hierarchy. Your goal is to minimize the number of nullable columns and to convince yourself (and your DBA) that a denormalized schema won’t create problems in the long run. © JBoss, Inc. 2003, 2004. 13
  • 14. Professional Open Source™  If you do require polymorphic associations or queries, and subclasses  declare many properties (subclasses differ mainly by the data they hold), lean toward table-per-subclass. Or, depending on the width and depth of your inheritance hierarchy and the possible cost of joins versus unions, use table-per-concrete-class. © JBoss, Inc. 2003, 2004. 14