You get a bonus - 1 coin for daily activity. Now you have 1 coin

The object-relational gap and impedance mismatch

Lecture



Object-relational impedance mismatch is a set of conceptual and technical difficulties that are often encountered when a relational database management system (RDBMS) is used by a program written in an object-oriented style, especially when objects or class definitions are mapped to a database table or relational schema.

Object-relational impedance mismatch is a set of conceptual and technical difficulties that are often encountered when a relational database management system (RDBMS) is currently being served by (several application programs or) application programs written in an object-oriented programming language or style, particularly because objects or class definitions must be mapped to database tables defined by a relational schema.

The term object-relational impedance mismatch comes from the electrical engineering term impedance matching.

(object-relational impedance mismatch).

Gap and mismatch

Object-oriented concept

Encapsulation

Object-oriented programs are designed with representation-hiding techniques in mind. Within the object-oriented style, the relevant properties of a given object should not be exposed through any interface. Nevertheless, object-relational mapping necessarily exposes the object's core content to interaction with an interface that the object's implementation cannot specify. Thus, object-relational mapping violates the object's encapsulation.

Access

In relational thinking, "private" versus "public" access is a relative rather than absolute characteristic of a data state, unlike in the object-oriented model. Relational and OO models often conflict over the relativity versus absolutism of classifications and characteristics.

Imitation and polymorphism

In the object-oriented paradigm, objects have interfaces that together provide the only access to the internal parts of the object. The relational model, on the other hand, makes use of derived relation variables to provide different perspectives and constraints to ensure integrity. Likewise, important OOP concepts for object classes, such as inheritance and polymorphism, are not supported by relational databases.

Mapping to relational concepts

A correct mapping between relational and object-oriented concepts can be achieved if the relational database tables are linked to the associations found in object-oriented analysis.

Differences in data types

An important mismatch between existing relational and OO languages is the difference in type systems. The relational model strictly forbids by-reference attributes (or pointers), while OO languages expect pass-by-reference behavior. Scalar types and their operator semantics can differ significantly between models, causing problems in mapping. For example, most SQL systems support string types with different collation types and maximum-length constraints (open-ended text types tend to reduce performance), while most OO languages treat collation only as an argument to a sorting procedure, with string size inherently tied to available memory. A subtler but related example: SQL systems often ignore trailing spaces in strings for comparison purposes, whereas OO string libraries generally do not.

Mismatches

Objects (instances) reference one another and therefore form a graph in the mathematical sense (a network including loops and cycles). Relational schemas, by contrast, are tabular and based on relational algebra, which defines related heterogeneous tuples (grouping data fields into a «row» with different types for each field).

Object-oriented concepts

Encapsulation

Object-oriented programs are well designed using techniques that allow the creation of encapsulated objects whose internal representation can be hidden. Within an object-oriented structure, the underlying properties of a given object are expected not to be exposed to any interface other than the one implemented together with the object. However, most object-relational mappings expose the object's underlying content to interaction with an interface that the object's implementation cannot specify. Consequently, this object-relational mapping violates the object's encapsulation, since many object-relational mappings automatically generate public fields corresponding to database columns. Some frameworks instead use metaprogramming techniques, which avoid violating encapsulation.

Accessibility

In relational thinking, «private» access versus «public» access depends on need. In the object-oriented (OO) model, this is an absolute characteristic of a data state. Relational and object-oriented models often conflict over the relativity versus absolutism of classifications and characteristics.

Interface, class, inheritance, and polymorphism

In the object-oriented paradigm, objects have interfaces that together provide the sole access to the internals of that object. The relational model, on the other hand, uses derived relation variables (views) to provide different points of view and constraints to ensure integrity. Likewise, the core OOP concepts of object classes, inheritance, and polymorphism are not supported by relational database systems.

Mapping to relational concepts

A correct mapping between relational and object-oriented concepts can be achieved if relational database tables are linked together to reflect the associations found in object-oriented analysis.

Differences in data types

The main mismatch between existing relational and object-oriented languages is the difference in type systems. The relational model strictly forbids the use of by-reference attributes (or pointers), whereas object-oriented languages accept and expect by-reference behavior. Scalar types and their operator semantics can differ greatly across models, causing problems when mapping.

For example, most SQL systems support string types with various collations and bounded maximum lengths (open-ended text types tend to reduce performance), while most object-oriented programming languages treat collation only as an argument to sorting procedures, with string size inherently tied to available memory. A subtler but related example: SQL systems often ignore trailing spaces in a string for comparison purposes, whereas OO string libraries do not. As a rule, it is not possible to create new data types by restricting the possible values of other primitive types in an object-oriented language.

Structural and integrity differences

Another mismatch relates to differences in the structural and integrity aspects of the contrasting models. In object-oriented languages, objects can consist of other objects - often to a high degree - or depend on a more general definition. This can make mapping to relational schemas less straightforward. This is because relational data is typically represented in a named set of global, non-nested relation variables. The relations themselves, being sets of tuples all conforming to a single header (see relational tuple calculus), have no ideal counterpart in object-oriented languages. Constraints in object-oriented languages are usually not declared as such but appear as exception-guarding logic surrounding code that operates on encapsulated internal data. The relational model, on the other hand, requires declarative constraints for scalar types, attributes, relation variables, and the database as a whole.

Manipulative differences

However, semantic differences are especially evident in the manipulative aspects of the contrasting models. The relational model has an internal, relatively small, and well-defined set of primitive operators for use in queries and data manipulation, whereas object-oriented programming languages usually handle queries and manipulation through custom or low-level, register- and pointer-based, path-dependent imperative operations. Some object-oriented languages support declarative query sublanguages, but since object-oriented languages typically deal with lists and possibly hash tables, the manipulative primitives are necessarily different from the set-based operations of the relational model.

Transactional differences

Concurrency and transaction aspects also differ substantially. In particular, transactions - the smallest unit of work performed by databases - in relational databases are much larger than any operations performed by classes in object-oriented languages. Transactions in relational databases represent dynamically bounded sets of arbitrary data manipulations, whereas the granularity of transactions in an object-oriented language is usually at the level of individual assignments to fields of primitive types. In general, object-oriented languages have no counterpart to isolation or durability, so atomicity and consistency are guaranteed only when writing to fields of these primitive types.

The object-relational gap and impedance mismatch

Figure 3 - Our conceptual framework for impedance mismatch, including ORM strategies

Level impedance mismatch
Paradigm Issues related to the incompatibility between
two different views of a concept from the universe
of discourse: one as a network of interacting
objects; the other as a set of relations.
Language Issues related to the incompatibility of data
structures between object and relational
languages. Lammel calls this
canonical mapping. In this article we will use
the term pattern in Keller's context, as
an outline of the solution description.
Schema Issues related to maintaining two
representations of a defined concept, described
in different languages.
Instance Issues related to storing and retrieving
an object in the context of an object-relational
application.

Resolving the impedance mismatch

Work on the impedance mismatch problem for object-oriented programs begins with recognizing the differences in the specific logical systems used. The mismatch is then either minimized or compensated for.

Alternative architectures

The object-relational impedance mismatch problem is not a universal problem between object-oriented objects and databases. As the name suggests, this impedance problem arises only with relational databases. The most common solution to this problem is to use an alternative database, such as a NoSQL or XML database.

Minimization

Several attempts have been made to create object-oriented database management systems (OODBMS) that would avoid the impedance mismatch problem. However, in practice they have proven less successful than relational databases, partly because of the limitations of object-oriented principles as a foundation for a data model. Research has been carried out on extending the database-like capabilities of object-oriented languages using concepts such as transactional memory.

One common solution to the impedance mismatch problem is to overlay domain logic and structure. In this scheme, an object-oriented language is used to model certain relational aspects at runtime, rather than attempting a more static mapping. Frameworks that use this method typically have a tuple analog, usually as a «row» in a «dataset» component or as a generic «entity instance» class, as well as an analog for a relation. The advantages of this approach can include:

  • Simple ways to build frameworks and automation for the transport, presentation, and validation of domain data.
  • Smaller code size; faster compile and load times.
  • The ability to change the schema dynamically.
  • Avoids namespace issues and semantic mismatch.
  • Expressive constraint validation
  • No need for complex mapping

The disadvantages can include:

  • Lack of static type "safety" checks. Typed accessors are sometimes used as one way to mitigate this.
  • Possible runtime overhead for creation and access.
  • Inability to natively use unique object-oriented aspects such as polymorphism.

Compensation

Mixing levels of discourse in object-oriented application code creates problems, but some common mechanisms are used to compensate for them. The biggest challenge is providing framework support, data-manipulation automation, and presentation patterns at the level of discourse in which the domain data is modeled. To address this, reflection and/or code generation are used. Reflection allows code (classes) to be treated as data, thereby enabling automation of data transport, presentation, integrity, and so on. Generation solves the problem by treating entity structures as input to code-generation tools or metaprogramming languages that mass-produce classes and supporting infrastructure. Both of these schemes can still be subject to certain anomalies when these levels of discourse merge. For example, generated entity classes will typically have properties that correspond to the domain (e.g., name, address) as well as properties that provide state management and other infrastructure plumbing (e.g., IsModified).

Disagreements

Christopher J. Date and others have argued that a truly relational DBMS would not create such a problem, , since domains and classes are essentially the same thing. Native mapping between classes and relational schemas is a fundamental design mistake; and individual tuples in a database table (relation) should be viewed as establishing relationships between objects, not as representations of complex objects themselves. However, this view tends to diminish the influence and role of object-oriented programming, treating it as little more than a field-type management system.

Impedance mismatch arises when programming between domain objects and the user interface. Complex user interfaces that allow operators, managers, and other non-programmers to access and manage database records often require deep knowledge of the nature of various database attributes (beyond name and type). In particular, it is considered good practice (from the standpoint of end-user performance) to design user interfaces so that the interface prevents the entry of illegal transactions (those that would cause database constraint violations); this requires that much of the logic present in relational schemas be duplicated in the code.

Certain code-development platforms can make use of certain forms of logic represented in the database schema (such as referential integrity constraints), so that such problems are solved in a standard and generic way through library procedures, rather than by ad hoc code written for the case at hand.

It has been argued that SQL, due to its very limited set of domain types (and other perceived shortcomings), makes it difficult to properly model objects and domains; and that SQL is a very inefficient and ineffective interface between a DBMS and an application program (whether written in an object-oriented style or not). However, SQL is currently the only widely adopted database language on the market; using vendor-specific query languages is considered bad practice whenever it can be avoided. Other database languages, such as Business System 12 and Tutorial D, have been proposed, but neither has achieved widespread adoption among DBMS vendors.

In current versions of major «object-relational» DBMSs, such as Oracle and Microsoft SQL Server, the above point may no longer matter. With these mechanisms, the functionality of a given database can be arbitrarily extended with stored code (functions and procedures) written in a modern object-oriented language (Java for Oracle and Microsoft's .NET language for SQL Server), and these functions can in turn be invoked in SQL statements transparently: that is, the user neither knows nor cares that these functions/procedures were not originally part of the database engine. Modern software development paradigms are fully supported: thus, a set of library procedures can be created that can be reused across multiple database schemas.

These vendors chose to support the integration of an object-oriented language into the DBMS back end because they realized that, despite the ISO SQL-99 committee's attempts to add procedural constructs to SQL, SQL will never have the rich set of libraries and data structures that modern application programmers take for granted, and it makes sense to use them as directly as possible rather than trying to extend the base SQL language. Consequently, the line between "application programming" and "database administration" is now blurred: reliably implementing features such as constraints and triggers may often require a person with both DBA and OO programming skills, or a partnership between people who combine these skills. This fact is also relevant to the "separation of responsibilities" issue discussed below.

Some, however, would point out that this claim is debatable because: (1) DBMSs were never intended to facilitate object modeling, and (2) SQL should generally be regarded merely as a lossy or inefficient interface when one tries to find a solution for which DBMSs were not designed. SQL performs very efficiently the task it was designed for, namely querying, sorting, filtering, and storing large data sets. Some would further note that embedding object-oriented programming language functionality in the back end simply encourages poor architectural practice, since it allows high-level application logic to leak into the data layer, which runs counter to the RDBMS approach.

This is where the «canonical» copy of the state resides. The database model generally assumes that the database management system is the single authoritative store of state concerning the enterprise; any copies of such state held in the application program are merely temporary copies (which may become stale if the underlying database record is subsequently changed by a transaction). Many object-oriented programmers prefer to regard the in-memory representations of the objects themselves as the canonical data and to treat the database as a backing store and persistence mechanism.

Another contentious issue is the proper division of responsibility between application programmers and database administrators (DBAs). It is often the case that necessary changes to application code (to implement a requested new feature or functionality) require corresponding changes to the database definition; in most organizations, the DBA is responsible for the database definition. Because of the need to keep a production database system running 24 hours a day, many DBAs are reluctant to make changes to database schemas that they consider unnecessary or excessive, and in some cases refuse to do so at all. Using development databases (in addition to production systems) can help to some extent; but once the newly developed application "goes live," the DBA will need to approve any changes. Some programmers consider this irreconcilable;

However, in organizations with a dysfunctional relationship between DBAs and developers, the problem described above should not arise, since the decision to change the database schema or not will depend solely on business needs: for example, a new requirement to store additional data, or an effort to improve the performance of a business-critical application, will trigger a schema change.

Philosophical differences

The key philosophical differences between the object-oriented and relational models can be summarized as follows:

  • Declarative versus imperative interfaces - relational thinking tends to use data as interfaces rather than behavior as interfaces. It therefore has a declarative bias in its design philosophy, in contrast to the behavioral bias of OO. (Some relational proponents suggest using triggers, stored procedures, and so on to provide complex behavior, but this is not the usual view.)
  • Binding to schema - objects need not necessarily follow a «parent schema» for which attributes or accessors an object has, whereas table rows must follow the schema of the table. A given row must belong to one and only one table. The closest thing to this in the object-oriented approach is inheritance, but it typically has a tree shape and is optional. Dynamic database systems that allow ad hoc columns to be created can loosen schema constraints, but such systems are either currently rare or their classification as «relational» is questionable.
  • Access rules - in relational databases, access to and modification of attributes is done via predefined relational operators, whereas an object-oriented object allows each class to create its own interface and state-modification methods. From the object-oriented "self-governing noun" point of view, each object is granted an independence that the relational model does not allow. This is the «standards versus local freedom» debate. OO tends to argue that relational standards limit expressiveness, while relational proponents suggest that adherence to rules allows for more abstract mathematical reasoning, integrity, and design consistency.
  • Relationship between nouns and verbs - the object-oriented approach encourages a tight coupling between verbs (actions) and nouns (entities) on which the operations act. The resulting tightly coupled object, containing both nouns and verbs, is usually called a class, or in object-oriented analysis, a concept. In relational designs, there is generally no assumption that there is anything natural or logical about such tight associations (other than relational operators).
  • Object identity - objects (other than immutable ones) are generally considered unique; two objects that are in the same state at a given moment are not considered identical. Relations, on the other hand, have no inherent concept of such identity. Nevertheless, it is common practice to fake "identity" for database records using globally unique candidate keys, although many consider this poor practice for any database record that does not have a one-to-one correspondence with a real-world entity. (Relations, like objects, can use domain keys if they exist in the outside world for identification purposes.) In practice, relational systems strive for and support «persistent» and verifiable identification methods, whereas object identification methods tend to be temporary or situational.
  • Normalization - relational normalization techniques are often ignored by object-oriented designs. However, this may simply be a bad habit rather than a built-in feature of object-oriented programming. An alternative view is that a set of objects linked together by pointers of a certain type is equivalent to a network database, which in turn can be viewed as an extremely denormalized relational database.
  • Schema inheritance - most relational databases do not support schema inheritance. Although such a feature could theoretically be added to reduce conflict with OOP, relational proponents are less likely to believe in the usefulness of hierarchical taxonomies and subtypes, since they tend to view set-based taxonomies or classification systems as more powerful and flexible than trees. Proponents of object-oriented programming point out that inheritance/subtyping models need not be limited to trees (although this is a limitation in many popular object-oriented languages, such as Java), but non-tree OO solutions are considered more difficult to formulate than the set-based management techniques on the subject preferred by relational proponents. At the very least, they differ from the techniques commonly used in relational algebra.
  • Structure versus behavior - OO primarily focuses on ensuring a sound program structure (maintainable, understandable, extensible, reusable, secure), whereas relational systems focus on the behavior of the resulting runtime system (efficiency, adaptability, fault tolerance, liveness, logical integrity, etc.). Object-oriented methods generally assume that the primary user of object-oriented code and its interfaces is the application developer. In relational systems, the end user's opinion of the system's behavior is sometimes considered more important. However, relational queries and «views» are common techniques for presenting information in application- or task-specific configurations. In addition, relational systems do not forbid creating local or application-specific structures or tables, although many common development tools do not provide this capability directly, assuming that objects will be used instead. This makes it difficult to determine whether a stated non-developer's view of relational systems is inherent to the relational model itself or simply a product of current practice and tool-implementation assumptions.
  • Set and graph relationships - relationships between different elements (objects or records) tend to be handled differently in different paradigms. Relational relationships are typically based on idioms drawn from set theory, while object relationships lean toward idioms borrowed from graph theory (including trees). Although each can represent the same information as the other, the approaches they provide for accessing and managing that information differ.

As a result of the object-relational impedance mismatch, proponents of both sides of the debate often argue that the other technology should be abandoned or scaled back. Some database proponents consider traditional «procedural» languages more compatible with DBMSs than many object-oriented languages, or suggest using a less object-oriented style. (Specifically, it is argued that long-lived domain objects should not exist in application code; any such objects that do exist should be created when a query is executed and destroyed once the transaction or task is complete.) Conversely, some object-oriented proponents argue that more OO-friendly persistence mechanisms, such as OODBMS, should be developed and used, and that relational technology should be discontinued. Many (if not most) programmers and database administrators hold neither of these views, and regard the object-relational impedance mismatch as simply a fact of life that information technology has to deal with.

It is also argued that O/R mapping pays off in some situations, but is probably oversold: alongside its drawbacks it does have advantages. Skeptics note that it is worth thinking carefully before using it, since in some cases it will provide no benefit at all.

Approaches to combining object and relational databases

Many users are interested in a combined approach that would let them take advantage of object databases without giving up their relational databases entirely. Such solutions do exist. If migrating from a relational database to an object database is too costly, then using the latter as an extension and complement to relational DBMSs is often a more economical alternative. Compromise solutions make it possible to strike a balance between objects and relational tables (Figure 3).

.The object-relational gap and impedance mismatch

Figure 2. Possible approaches to combining RDBMS and OODBMS

Object-relational adapters. This method involves using a so-called object-relational adapter, which automatically extracts program objects and stores them in relational databases. The object-oriented application runs as an ordinary user of the DBMS. Despite some reduction in performance, this option allows programmers to focus entirely on object-oriented development. In addition, all applications already existing within the enterprise can still access the data stored in relational form.

Some object DBMSs, such as GemStone from GemStone Systems, can themselves act as a powerful object-relational adapter, allowing object-oriented applications to access relational databases.

Object-relational adapters, such as Hewlett-Packard's Odapter for the Oracle DBMS, can be used successfully in many areas, for example as middleware linking object-oriented applications with relational DBMSs.

Object-relational gateways. With this method, the user interacts with the database using the OODBMS language, and the gateway replaces all the object-oriented elements of that language with their relational counterparts. Here again, one pays a price in performance. For example, the gateway must convert objects into a set of links, generate original identifiers (OID) for the objects, and pass this to the relational database. The gateway must then, each time the relational DBMS interface is used, convert the OID found in the database into the corresponding object stored in the RDBMS.

Performance in the two approaches discussed depends on the method of accessing the relational database. Every RDBMS consists of two layers: the data manager layer and the storage manager layer. The former processes SQL statements, while the latter maps data to storage. A gateway or adapter can interact either with the data layer (i.e., access the RDBMS via SQL) or with the storage layer (via low-level procedure calls). Performance in the first case is much lower (for example, Hewlett-Packard's OpenODB system, which can act as a gateway, only supports the high-level approach).

Hybrid DBMSs. Another solution could be to create hybrid object-relational DBMSs capable of storing both traditional tabular data and objects. Many analysts believe that the future belongs to such hybrid databases. Leading relational DBMS vendors are beginning (or planning) to add object-oriented facilities to their products. In particular, Sybase and Informix are planning to introduce object support in upcoming versions of their DBMSs. Independent firms intend to pursue similar developments. For example, Shores is preparing to equip Oracle8 with object-oriented facilities, with a release planned for late 1996.

On the other hand, object DBMS vendors, such as Object Design, recognize that object-oriented databases are unlikely to replace relational DBMSs in the foreseeable future. This is forcing them to build gateways to support relational and hierarchical databases, or various kinds of interfaces, a characteristic example being Ontos's object-relational interface, the Ontos Integration Server, used together with its Ontos/DB OODBMS. [Source 3]

Advantages of ORD

  • The main advantages of the extended relational model are component reuse and sharing. When properly designed with the new capabilities in mind, this approach allows organizations to take advantage of the new extensions in an evolutionary way, without losing the benefits gained from using the components and features of an already existing database.
  • Extended SQL capabilities, in particular server-side programming facilities that provide the ability to define UDTs, stored procedures and functions, triggers, and so on, make it possible to move an increasing share of application logic onto the database server.
  • When designing a database application, there are three alternatives: application logic can be implemented on the client side, on the application server, or on the database server. Clearly, each alternative has its place, and each can prove to be the winning choice in a particular situation.

Disadvantages of ORD

  • An obvious drawback of the ORDBMS approach is its complexity and the associated increased costs. The simplicity and clarity inherent in the relational model are lost when using such types of extensions. Some believe that RDBMS extensions are intended for a small number of applications, and that optimal performance cannot be achieved in the latter using existing relational technology. And many other issues, right down to terminology.
  • Extensive capabilities can also be counted among the drawbacks, since some features largely contradict the teachings of Edgar Codd, which argued for the desirability of database independence from applications. Database independence from applications often looks like a very attractive idea, but achieving it means it is reasonable to give up many SQL extensions.
  • Another problem, unrelated to the capabilities of server-side implementation of application logic, is the use of collection types in databases. Support in the SQL standard for multiset types, whose elements can be values of anonymous row types, now provides the ability to define nested tables with an arbitrary (theoretically unlimited) level of nesting. Since all values stored in the database remain strictly typed, this capability does not conflict with the basic requirement of first normal form inherited from the relational data model, but essentially provides an approach to directly modeling hierarchical structures.

See also

  • Object-relational mapping
  • Object-relational database
  • [[b7707]]
  • [[b5340]]
  • [[b7705]]
  • [[b4701]]
  • [[b8942]]

See also

created: 2021-11-25
updated: 2026-03-09
497



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases, knowledge and data warehousing. Big data, DBMS and SQL and noSQL"

Terms: Databases, knowledge and data warehousing. Big data, DBMS and SQL and noSQL