Top 10 Must Have Features in O/R Mapping Tools
Feature 5: Object inheritance
As you already know, a very important aspect of object-oriented programming is inheritance. However, relational databases do not automatically provide inheritance in the relational model. But, there are a number of patterns on how to map object inheritance to a relational database. And, a good O/R mapping tool must provide this capability.
Here are a few ways in which object inheritance is mapped to relational databases.
- One table per object
This is the most popular and flexible pattern. In this, each object is mapped to its own table in the database. And, there is a one-to-one relationship between every base object and its derived object. The foreign key of this relationship is kept in the derived object. It is the most flexible because without changing the structure of any existing tables, we can keep adding to the inheritance hierarchy. However, it is not the most efficient for loading both base and derived objects because a separate "load" is done for each object. - One table for all objects
In this pattern, the base object and all the derived objects are represented in one table in the database. This table contains columns representing attributes from all the objects. It is the most efficient for loading and saving data but is very limited because adding a new object to the inheritance requires changing the structure of an existing table in the database that is highly undesirable. Keeping this in mind, the O/R mapping tool must support at least the "One table per object" approach and if it can also support the second approach that is icing on the cake. The generated code for base and derived classes should handle the following situations:- Insert and update operations
The derived class must first ask the base class to do Insert or Update and then do its own. But both the base and derived class operations must be performed in one transaction. - Delete operation
Unlike the insert and update operations, the delete operation is performed first on the derived object and then on the base object. However, both must be done in one transaction. - Load operation
The load operation in the derived class must also call load on the base class and both of these should be done in one transaction.
- Insert and update operations
Previous Page | Next Page
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
If you found this page useful, bookmark and share it on:
If you are familiar with RSS feeds, you can also sign up for our free blog feed. Our RSS feed is updated in real-time while our newsletter is updated daily.
