CSC/ECE 517 Fall 2009/wiki3 12 Patterns for ORM: Difference between revisions
Line 2: | Line 2: | ||
[http://en.wikipedia.org/wiki/Object-relational_mapping Object-relational mapping] is not trivial. Apart from being based on Software Engineering principles like coupling, cohesion and polymorphism, the object paradigm focuses on building applications out of objects that have both data and behavior. However, the relational paradigm is based on mathematical principles and focuses primarily on storing data. If only data objects were to be mapped to the relational database the procedure would have been fairly straightforward. With the growing complexities of object models, concepts like aggregation, inheritance, polymorphism, association between classes, and data type (smarted than SQL data types) have to be mapped to relational table structure. The table below highlights the fundamental mismatch between object oriented data model and relational data storage. | [http://en.wikipedia.org/wiki/Object-relational_mapping Object-relational mapping] is not trivial. Apart from being based on Software Engineering principles like coupling, cohesion and polymorphism, the object paradigm focuses on building applications out of objects that have both data and behavior. However, the relational paradigm is based on mathematical principles and focuses primarily on storing data. If only data objects were to be mapped to the relational database the procedure would have been fairly straightforward. With the growing complexities of object models, concepts like aggregation, inheritance, polymorphism, association between classes, and data type (smarted than SQL data types) have to be mapped to relational table structure. The table below highlights the fundamental mismatch between object oriented data model and relational data storage. | ||
=='''Inheritance Mapping'''== | =='''[http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html Inheritance Mapping]'''== | ||
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] in [http://en.wikipedia.org/wiki/Object-oriented_design Object Oriented Design] makes it difficult to map between object and relation databases. In this pattern, there is mapper class for each domain class that will save and load data for the domain class [8]. Mapper class allows both abstract and concrete classes to handle their own O/R mapping[8]. | |||
For example: - To find an employee “John”:- | |||
Application calls find () method on concrete mapper object and instantiate a new Executive object. The find () will pass this executive object and database record to load () of Executive. This in turn will call the load () of Superclass. When all loads return, find returns the filled object. | |||
Mappers loading and saving the domain objects is determined by the inheritance mapping. This inheritance hierarchy is represented in the database as follows:- | |||
*Single Table Inheritance | |||
*Class Table Inheritance | |||
*Concrete Table Inheritance | |||
Choosing a mapping scheme depends on speed requirement, whether database is shared and type of RDBMS. | |||
==='''Single Table Inheritance'''=== | ==='''Single Table Inheritance'''=== | ||
==='''Class Table Inheritance '''=== | ==='''Class Table Inheritance '''=== | ||
==='''Concrete Table Inheritance'''=== | ==='''Concrete Table Inheritance'''=== | ||
=='''Association Mapping'''== | =='''Association Mapping'''== | ||
==='''One-to-one mapping'''=== | ==='''One-to-one mapping'''=== |
Revision as of 17:52, 17 November 2009
Overview
Object-relational mapping is not trivial. Apart from being based on Software Engineering principles like coupling, cohesion and polymorphism, the object paradigm focuses on building applications out of objects that have both data and behavior. However, the relational paradigm is based on mathematical principles and focuses primarily on storing data. If only data objects were to be mapped to the relational database the procedure would have been fairly straightforward. With the growing complexities of object models, concepts like aggregation, inheritance, polymorphism, association between classes, and data type (smarted than SQL data types) have to be mapped to relational table structure. The table below highlights the fundamental mismatch between object oriented data model and relational data storage.
Inheritance Mapping
Inheritance in Object Oriented Design makes it difficult to map between object and relation databases. In this pattern, there is mapper class for each domain class that will save and load data for the domain class [8]. Mapper class allows both abstract and concrete classes to handle their own O/R mapping[8].
For example: - To find an employee “John”:- Application calls find () method on concrete mapper object and instantiate a new Executive object. The find () will pass this executive object and database record to load () of Executive. This in turn will call the load () of Superclass. When all loads return, find returns the filled object. Mappers loading and saving the domain objects is determined by the inheritance mapping. This inheritance hierarchy is represented in the database as follows:-
- Single Table Inheritance
- Class Table Inheritance
- Concrete Table Inheritance
Choosing a mapping scheme depends on speed requirement, whether database is shared and type of RDBMS.