Object–relational impedance mismatch: Difference between revisions

Content deleted Content added
m Reverted edits by 88.109.153.77 (talk) (HG) (3.4.12)
Rhino02 (talk | contribs)
No edit summary
 
(35 intermediate revisions by 22 users not shown)
Line 1:
{{short description|Set of conceptual and technical difficulties}}
{{Multiple issues|
{{Peacock|date=August 2020}}
{{Weasel|date=August 2020}}
{{More footnotes|date=August 2020}}
'''Object–relational impedance mismatch''' is a set of difficulties going between data in relational data stores and data in ___domain-driven object models. [[relational database management system | Relational Database Management Systems]] (RDBMS) is the standard method for storing data in a dedicated database, while [[Object-oriented programming|object-oriented]] (OO) programming is the default method for business-centric design in programming languages. The problem lies in neither relational databases nor OO programming, but in the conceptual difficulty mapping between the two logic models. Both logical models are differently implementable using database servers, programming languages, design patterns, or other technologies. Issues range from application to enterprise scale, whenever stored relational data is used in ___domain-driven object models, and vice versa. Object-oriented data stores can trade this problem for other implementation difficulties.
}}
The '''object–relational impedance mismatch''' is a set of conceptual and technical difficulties that are often encountered when a [[relational database management system]] (RDBMS) is being served by an application program (or multiple application programs) written in an [[object-oriented]] [[programming language]] or style, particularly because objects or class definitions, must be [[object–relational mapping|mapped]] to database tables defined by a relational schema.
 
The term ''object–relational impedance mismatch'' is derivedcomes from the [[electricalimpedance engineeringmatching]] termin ''[[impedanceelectrical matchingengineering]]''.
 
== Mismatches ==
ObjectsOO (instances)mathematically reference one another and therefore form ais [[directed graph]]s, inwhere theobjects mathematicalreference senseeach (a network including loops and cycles)other. Relational schemasis are,tuples in contrast,tables tabular and based onwith [[relational algebra]],. whichTuples defines linked heterogeneous tuples (groupings ofare data fields grouped into a "row" with differenttyped types for each field), wherefields. linksLinks are always reversible (foreign keys can be followed backwards, as INNER JOIN is symmetric), whichto isfollow aforeign characteristickeys morebackwards), akin toforming [[Graph_(discrete_mathematics)#Graph|undirected graphs]].
 
=== Object-oriented concepts ===
 
==== Encapsulation ====
[[object (computer science)|Object]] [[Encapsulation (object-oriented programming)|encapsulation]] hides internals. Object properties only show through implemented interfaces. However, many [[object–relational mapping|ORM]]s expose the properties publicly to work with database columns. Metaprogramming ORMs avoid violating encapsulation.
Object-oriented programs are designed with techniques that result in [[Encapsulation (object-oriented programming)|encapsulated]] [[object (computer science)|objects]] whose internal representation can be hidden. In an object-oriented framework, the underlying properties of a given object are expected not to be exposed to any interface outside of the one implemented alongside the object. However, most [[object–relational mapping]] approaches expose the underlying content of an object to interact with an interface that the object implementation cannot specify. Hence, this object–relational mapping violates the encapsulation of the object, since many object–relational mappers automatically generate public fields corresponding to database columns.
A few frameworks use Metaprogramming techniques instead, thus avoiding violating encapsulation.
 
==== Accessibility ====
In relational thinking, "privatePrivate" versus "public" access is relativeneed-based toin needrelational. In the object-oriented (OO) model it is anabsolutely absolute characteristic of the data's stateclass-based. The relational and OO models often have conflicts overThis relativity versus absolutism of classifications and characteristics clashes.
 
==== Interface, class, inheritance and polymorphism ====
UnderObjects anmust object-oriented paradigm, objects haveimplement [[Interface (computer science)|interfaces]] thatto togethernot provide the only access to theexpose internals of that object. TheRelational relationaluses model, on the other hand, utilizes derived relation variables ([[View (database)|views]]) to provide varyingvary perspectives and constraints to ensure integrity. Similarly,It essentiallacks OOPOO concepts forlike [[class (computer science)|classes]] of objects, [[Inheritance (computerobject-oriented scienceprogramming)|inheritance]] and [[polymorphism (computer science)|polymorphism]], are not supported by relational database systems.
 
==== Mapping to relational concepts ====
AIn properorder mappingfor betweenan relationalORM conceptsto andwork object-orientedproperly, conceptstables canthat beare madelinked ifvia relational[[Foreign databasekey|Foreign tablesKey]]/[[Primary are linked{{Elucidatekey|date=AprilPrimary 2015}}Key]] relations need to be mapped to [[association (object-oriented programming)|associations]] found in [[object-oriented analysis and design|object-oriented analysis]].
 
=== Data type differences ===
A major mismatch between existing relational and OO languages is the [[type system]] differences. The relational model strictlyRelational prohibits by-reference attributes (ore.g. [[pointer (computer programming)|pointers]]), whereaswhile OO languages embrace and expectembraces by-reference behavior. [[Scalar (computing)|Scalar types]] and their operator [[semantics]] can be vastly differentdiffer between the modelsthem, causing problems inimpeding mapping.
 
For example, most [[SQL]] systems supportsupports [[String (computer science)|string]] typess with varying [[collation]]s and constrained maximum lengths (open-ended text types tend tofaster hinderthan performancewithout), whileand most[[collation]]s. OO languages considerhas collation only as an argument towith [[Sorting algorithm|sort routines]] and strings arelimited intrinsicallyonly sized to availableby memory. A more subtle, but related example is that SQL systems oftenusually ignoreignores trailing [[Whitespace (computer science)|white spacewhitespace]] induring acomparison string[[SQL forsyntax#Data the purposes of comparisontypes|char]], whereasbut OO string libraries do not. ItOO is typicallydoes not possiblenewtype tousing constructconstraints new data types as a matter of constraining the possible values of other primitive types in an OOon languageprimitives.
 
=== Structural and integrity differences ===
Objects can comprise other objects or specialize. Relational is unnested, and a relation ([[tuple relational calculus|tuple]]s with the same header) does not fit in OO.
Another mismatch has to do with the differences in the structural and integrity aspects of the contrasted models. In OO languages, objects can be composed of other objects—often to a high degree—or specialize from a more general definition. This may make the mapping to relational schemas less straightforward. This is because relational data tends to be represented in a named set of global, unnested relation variables. Relations themselves, being sets of [[tuple]]s all conforming to the same header (see ''[[tuple relational calculus]]'') do not have an ideal counterpart in OO languages. Constraints in OO languages are generally not declared as such, but are manifested as exception raising protection logic surrounding code that operates on encapsulated internal data. The relational model, on the other hand, calls for [[Declarative programming|declarative]] constraints on scalar types, attributes, relation variables, and the database as a whole.
 
Relational uses [[Declarative programming|declarative]] constraints on scalar types, attributes, relation variables, and/or globally. OO uses exceptions protecting object internals.
 
=== Manipulative differences ===
TheRelational semanticuses differences are especially apparent in the manipulative aspects of the contrasted models, however. The relational model has an intrinsic, relatively small and well-defined set of primitivestandardized operators for usage in the query anddata manipulation of data, whereaswhile OO languagesuses generally handle query and manipulation through customper-builtclass or lowerper-level, case- and physical-access-path-specific [[Imperative programming|imperative]] operations. SomeAny OO languages do havedeclarative support is for declarative query [[sublanguage]]s, but because OO languages typically deal with lists and perhaps [[hash table]]s, the manipulative primitives are necessarily distinct from the [[Set (computer science)|set]]-baseds operations of thein relational model.{{Citation needed|date=November 2013}}
 
=== Transactional differences ===
TheRelational's concurrencyunit andis transaction aspects are significantly different also. In particular,the [[database transaction|transactionstransaction]], thewhich smallest unit of work performed by databases, are much larger in relational databases than areoutsizes any operationsOO performed by classes in OOclass languagesmethods. Transactions in relational databases are dynamically bounded sets ofinclude arbitrary data manipulationsmanipulation combinations, whereas the granularity of transactions in anwhile OO language is typically on the levelonly ofhas individual assignments to primitive-typed fields. In general, OO languages have no analogue oflacks isolation orand durability, so atomicity and consistency are only ensured when writing to fields of those primitivewith typesprimitives.
 
== Solving impedance mismatch ==
WorkingSolutions around the impedance mismatch problem for object-oriented programs startsstart with recognition ofrecognizing the differences inbetween the specific logic systems being employed. TheThis mismatchminimizes isor thencompensates eitherfor minimizedthe or compensated formismatch.<ref>[http://oro.open.ac.uk/18644/ A classification of object–relational impedance mismatch. Ireland, Christopher; Bowers, David; Newton, Mike and Waugh, Kevin (2009). A classification of object–relational impedance mismatch. In: First International Conference on Advances in Databases, Knowledge, and Data Applications (DBKDA), 1-6 Mar 2009, Cancun, Mexico. ]</ref>
 
=== Alternative architectures ===
The object–relational impedance mismatch problem is not a universal problem between OO and databases. As the name suggests, this impedance problem only occurs with [[relational database]]s. The most common solution to this problem is to use an alternative database, such as [[NoSQL]] or [[XML database]].
 
# ''NoSQL''. The mismatch is not between OO and DBMSes. Object-relational impedance mismatch is eponymously only between OO and '''R'''DBMSes. Alternatives like [[NoSQL]] or [[XML database]]s avoid this.
=== Minimization ===
# ''Functional-relational mapping''. [[List_comprehension|Comprehensions]] in functional programming languages are isomorphic with relational queries.<ref>{{cite web | url=https://nbviewer.org/github/phelps-sg/python-bigdata/blob/master/src/main/ipynb/relational-python.ipynb | title=Jupyter Notebook Viewer }}</ref> Some functional programming languages implement functional-relational mapping.<ref>{{cite web | url=https://scala-slick.org/doc/stable/introduction.html | title=Introduction · Slick }}</ref> The direct correspondence between comprehensions and queries avoids many of the problems of object-relational mapping.
There have been some attempts at building [[Object database|object-oriented database management systems]] (OODBMS) that would avoid the impedance mismatch problem. They have been less successful in practice than relational databases however, partly due to the limitations of OO principles as a basis for a data model.<ref>C. J. Date, Relational Database Writings</ref> There has been research performed in extending the database-like capabilities of OO languages through such notions as [[Software transactional memory|transactional memory]].
 
=== Minimization in OO ===
[[Object database]]s (OODBMS) to avoid the mismatch exist but only less successfully than relational databases. OO is a poor basis for schemas.<ref>C. J. Date, Relational Database Writings</ref> Future OO database research involves [[Software transactional memory|transactional memory]].
 
Another solution layers the ___domain and framework logic. Here, OO maps relational aspects at runtime rather than statically. Frameworks have a tuple class (also named row or entity) and a relation class (a.k.a dataset).
 
==== Advantages ====
* Straightforward paths to build frameworks and automation around data transport, presentation, and validation of ___domain data.
* Smaller, faster, quicker code{{Citation needed|date=July 2024}}
* Dynamic [[database schema]]
* Namespace and semantic match
* Expressive constraint checkingconstraints
* NoAvoids complex mapping necessary
 
Disadvantages==== mayDisadvantages include:====
One common solution to the impedance mismatch problem is to layer the ___domain and framework logic. In this scheme, the OO language is used to model certain relational aspects at runtime rather than attempt the more static mapping. Frameworks which employ this method will typically have an analogue for a tuple, usually as a "row" in a "dataset" component or as a generic "entity instance" class, as well as an analogue for a relation. Advantages of this approach may include:
* No static typing. Typed accessors mitigate this.
* Straightforward paths to build frameworks and automation around transport, presentation, and validation of ___domain data.
* Indirection performance cost
* Smaller code size; faster compile and load times.
* InabilityIgnores toconcepts natively utilize uniquely OO aspects, such aslike [[Polymorphism in object-oriented programming|polymorphism]].
* Ability for the [[Database schema|schema]] to change dynamically.
* Avoids the name-space and semantic mismatch issues.
* Expressive constraint checking
* No complex mapping necessary
Disadvantages may include:
* Lack of static type "safety" checks. Typed accessors are sometimes utilized as one way to mitigate this.
* Possible performance cost of runtime construction and access.
* Inability to natively utilize uniquely OO aspects, such as [[Polymorphism in object-oriented programming|polymorphism]].
 
=== Compensation ===
TheMixing mixing ofOO [[levels of discourse]] withinis OO application code presents problems, but there are some common mechanisms used to compensateproblematic. The biggest challenge is to provideMainly framework support compensates, automationby ofautomating data manipulation and presentation patterns, withinon the level of discourse in which the ___domain data is being modelledmodelling. To address this, [[Reflection (computer science)|reflectionReflection]] and/or [[Automatic programming|code generation]] are utilizedused. Reflection allowsaddresses code (classes) to be addressed as data andto thusallow provideautomatic automation of thedata transport, presentation, and integrity, etc. of the data. Generation addressesturns theschemas problem through addressing the entity structures as data inputs for code generation tools or meta-programming languages, which produce theinto classes and supporting infrastructure en massehelpers. Both of these schemes may still be subject to certainhave anomalies where thesebetween levels, of discourse merge. For instance,where generated entity classes willhave typicallyboth have___domain properties which map to the ___domain (e.&nbsp;g. Name, Address, Phone) as well as properties which provide state management and other framework infrastructureproperties (e.&nbsp;g. IsModified).
 
== Occurrence ==
Although object-relational impedance mismatches can occur with object-oriented programming in general, a particular area of difficulty is with [[objectObject–relational relationalmapping|object–relational mappermappers]]s (ORMs).<ref>[https://www.semanticscholar.org/paper/Object-Relational-Mapping-Revisited-A-Quantitative-Lorenz-Rudolph/708ac5e798b7e45b949d42e2f872549a3612e1e2 Object–Relational Mapping Revisited - A Quantitative Study on the Impact of Database Technology on O/R Mapping Strategies. M Lorenz, JP Rudolph, G Hesse, M Uflacker, H Plattner. Hawaii International Conference on System Sciences (HICSS), 4877-4886] (DOI:10.24251/hicss.2017.592)</ref> Since the ORM is often specified in terms of configuration, annotations, and restricted [[___domain-specific language]]s, it lacks the flexibility of a full programming language to resolve the impedance mismatch.
 
== Contention ==
{{weasel|section|date=January 2015}}
 
=== True RDBMS Modelmodel ===
It has been argued, by [[Christopher J. Date]] and others, thatsays a trulytrue [[relational DBMS]] wouldovercomes pose no suchthe problem,<ref>{{Citation | url=http://dbdebunk.blogspot.com.br/2012/08/type-vs-___domain-and-class.html | first1 = Christopher ‘Chris’ J | last1 = Date | first2 = Fabian | last2 = Pascal | author2-link = Fabian Pascal | title = Database debunkings | date = 2012-08-12 | orig-year = 2005 | contribution = Type vs. Domain and Class | publisher = Google | format = World Wide Web log | access-date = 12 September 2012}}.</ref><ref>{{Citation | first = Christopher ‘Chris’ J | last = Date | author-mask = 3 | chapter = 4. On the notion of logical difference | quote = Class seems to be indistinguishable from type, as that term is classically understood | page = 39 | title = Date on Database: writings 2000–2006 | publisher = Apress | year = 2006 | place = [[United States of America|USA]] | isbn = 978-1-59059-746-0 | series = The expert’s voice in database; Relational database select writings}}.</ref><ref>{{Citation | first = Christopher ‘Chris’ J | last = Date | author-mask = 3 | chapter = 26. Object/Relational databases | quote = ...any such ''rapprochement'' should be firmly based on the relational model | page = [https://archive.org/details/introductiontoda0000date/page/859 859] | title = An introduction to database systems | edition = 8th | publisher = Pearson Addison Wesley | year = 2004 | isbn = 978-0-321-19784-9 | chapter-url = https://archive.org/details/introductiontoda0000date/page/859 }}.</ref> as [[data ___domain|domains]] and [[class (computer science)|classes]] are essentially one and the same thingequivalent. A native mappingMapping between classesrelational and relational schemataOO is a fundamental design mistake;.<ref>{{Citation | last1 = Date | first1 = Christopher ‘Chris’ J | author1-link =Christopher Christopher_JJ._Date Date| last2 = Darwen | first2 = Hugh | author2-link = Hugh Darwen | title = The Third Manifesto | chapter = 2. Objects and Relations | quote = The first great blunder }}</ref> and that individualRelational tuples within a database table (relation) ought to be viewed as establishing relationships between entities;relate, not as representations for complexrepresent, entities themselves. However, this view tends to diminish the influence andOO's role ofbecomes object-oriented programming, using it as little more than a field typeonly managementmanaging systemfields.
 
=== Constraints and Illegalillegal Transactionstransactions ===
The impedance mismatch is in programming between the [[___domainDomain object]]s and the [[user interface]]s have mismatched impedances. SophisticatedProductive userUIs interfaces,should prevent illegal transactions ([[database constraint]] violations) to allowhelp operators, managers, and other non-programmers to access and manipulatemanage the recordsdata. inThis the database, often require intimaterequires knowledge about the nature of the various database attributes (beyond name and type). In particular, it's considered a good practice (from an end-user productivity point of view) to design user interfaces such that the UI prevents illegal transactions (those which cause a [[databasecode constraintsduplication|database constraintduplicates]] to be violated) from being entered; to do so requires much of the logic present in the relational schemata to be [[code duplication|duplicated]] in the code.
 
Certain code-development frameworks canFrameworks leverage certain forms of logic that are represented in the database's schema (such as referential integrity constraints), so that such issues are handled in a generic and standardother fashionschema throughinformation libraryto routinesstandardize ratherhandling thanaway ad hoc code written on afrom case-by-case basiscode.
 
=== SQL-Specificspecific Impedanceimpedance and Workaroundsworkarounds ===
It has been argued that [[SQL]], due to a very limited set oflacking ___domain types, (andimpedes otherOO alleged flaws) makes proper object and ___domain-modelling.{{Disputed difficult;inline|date=September and2024}} thatIt SQL constitutes a veryis lossy and inefficient interface between athe DBMS and anthe application program (whether written in an object-oriented styleOO or not). However, SQLmany isavoid currentlyNoSQL the only widely accepted common database language in the marketplace{{citation needed|reason=Many NOSQL vendors have reached wide popularity, e.g. Mongo|date=June 2015}}; useand ofalternative vendor-specific query languages is seen as a bad practice when avoidable. Other database languagesDBMSes suchalso asignore [[Business System 12]] and Tutorial D have been proposed; but none of these has been widely adopted by DBMS vendors.
 
Mainstream DBMSes like Oracle and Microsoft SQL Server solve this. OO code (Java and .NET respectively) extend them and are invokeable in SQL as fluently as if built into the DBMS. Reusing library routines across multiple schemas is a supported modern paradigm.
In current versions of mainstream "object–relational" DBMSs like Oracle and Microsoft SQL Server, the above point may be a non-issue. With these engines, the functionality of a given database can be arbitrarily extended through stored code (functions and procedures) written in a modern OO language (Java for Oracle, and a Microsoft .NET language for SQL Server), and these functions can be invoked in-turn in SQL statements in a transparent fashion: 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, one can create a set of library routines that can be re-used across multiple database schemas.
 
TheseOO vendorsis decidedin tothe supportbackend OO-languagebecause integrationSQL atwill thenever DBMSget back-endmodern becauselibraries theyand realizedstructures for today's thatprogrammers, despite the attempts of the ISO SQL-99 committee wanting to add procedural. constructs to SQL, SQL will never have the rich set of libraries and data structures that today's application programmers take for granted, and itIt is reasonable to leverageuse these asthem directly as possible rather than attempting to extend the corechanging SQL language. This Consequently,blurs the differencedivision of responsibility between "application programming" and "database administration" is now blurred: robust implementation of features suchbecause asimplementing constraints and triggers maynow oftenrequires requireboth anDBA individualand with dual DBA/OO-programming skills, or a partnership between individuals who combine these skills. This fact also bears on the "division of responsibility" issue below.
 
This contention may be moot. RDBMSes are not for modelling. SQL is only lossy when abused for modelling. SQL is for querying, sorting, filtering, and storing big data. OO in the backend encourages bad architecture as business logic should not be in the data tier.
Some, however, would point out that this contention is moot due to the fact that: (1) RDBMSes were never intended to facilitate object modelling, and (2) SQL generally should only be seen as a "lossy" or "inefficient" interface language when one is trying to achieve a solution for which RDBMSes were not designed. SQL is very efficient at doing what it was designed to do, namely, to query, sort, filter, and store large sets of data. Some would additionally point out that the inclusion of OO language functionality in the back-end simply facilitates bad architectural practice, as it admits high-level application logic into the data tier, antithetical to the RDBMS.
 
=== Location of Canonicalcanonical Copycopy of Datadata ===
HereRelational the "canonical" copy of state is located. The database model generally assumes thatsays the [[database management system]]DBMS is the only authoritative repository of state concerningand the enterprise;OO anyprogram's copies of such state held by an application programobjects are just that{{snd}} temporary copies (whichpossibly may be out of date,outdated if the underlying database record was subsequentlyis modified by a transactionconcurrently). ManyOO object-oriented programmers prefer to viewsays the in-memory representations of objects themselvesare as the canonical dataauthoritative, and view the databaseDBMS asis ajust backing store andfor persistence mechanism.
 
=== Division of Responsibilityresponsibility ===
New features change both code and schemas. The schema is the DBA's responsibility. DBAs are responsible for reliability, so they refuse programmers' unnecessary modifications. Staging databases help but merely move the approval to release time. DBAs want to contain changes to code, where defects are less catastrophic.
Another point of contention is the proper division of responsibility between application programmers and [[database administrator]]s (DBA). It is often the case that needed changes to application code (in order to implement a requested new feature or functionality) require corresponding changes in the database definition; in most organizations, the database definition is the responsibility of the DBA. Due to the need to maintain a production database system 24 hours a day many DBAs are reluctant to make changes to database schemata that they deem gratuitous or superfluous and in some cases outright refuse to do so. Use of developmental databases (apart from production systems) can help somewhat; but when the newly developed application "goes live" the DBA will need to approve any changes. Some programmers view this as intransigence; however the DBA is frequently held responsible if any changes to the database definition cause a loss of service in a production system—as a result, many DBAs prefer to contain design changes to application code, where design defects are far less likely to have catastrophic consequences.
 
More collaboration solves this. Schema change decisions should be from business needs. Novel data or performance boosts both modify the schema.
In organizations with a non-dysfunctional relationship between DBAs and developers, though, the above issue should not present itself, as the decision to change a database schema or not would only be driven by business needs: a new requirement to persist additional data or a performance boost of a critical application would both trigger a schema modification, for example.
 
== Philosophical differences ==
Key philosophical differences between the OO and relational models can be summarized as followsexist:
 
* '''Declarative vs. imperative interfaces'''{{snd}} Relational thinkinguses tendsdeclarative todata usewhile dataOO asuses interfaces, notimperative behavior as interfaces. ItFew thuscompensate has a declarative tilt in design philosophy in contrast to OO's behavioral tilt. (Somefor relational proponentswith suggesttriggers using triggers,and stored procedures, etc. to provide complex behavior, but this is not a common viewpoint.)
* '''Schema bound'''{{snd}} Relational limits rows to their entity schemas. OO's inheritance (tree or not) is similar. OO can also add attributes. New and few dynamic database systems unlimit this for relational.
* '''Schema bound'''{{snd}} Objects do not have to follow a "parent schema" for which attributes or accessors an object has, while table rows must follow the entity's schema. A given row must belong to one and only one entity. The closest thing in OO is inheritance, but it is generally tree-shaped and optional. Dynamic database systems that allow ad hoc columns may relax schema bound-ness, but such systems are either currently rare, or their classification as "relational" is in question.
* '''Access rules'''{{snd}} InRelational relationaluses databases, attributes are accessed and altered through predefined relationalstandardized operators, while OO allowsclasses eachhave classindividual to create its own state alteration interface and practicesmethods. The "self-handling noun" viewpoint of OO gives independence to each object that the relational model does not permit. This is a "standards versus local freedom" debate. OO tends to argue that relational standards limitmore expressivenessexpressive, whilebut relational proponents suggest the rule adherence allows more abstracthas math-like reasoning, integrity, and design consistency.
* '''Relationship between nouns and verbs'''{{snd}} An OO encourages a tight association between verbs (actions) and the nouns (entities) that the operations operate on. The resulting tightly bound entity containing both nouns and the verbs is usually called a [[class (computer science)|class]], oris ina OOnoun analysis,entity tightly associated with verb actions. This forms a [[Conceptual model (computer science)|concept]]. Relational designsdisputes generally do not assume there is anythingthe naturalnaturalness or logicallogicality aboutof suchthat tight associations (outside of relational operators)association.
* '''Object identity'''{{snd}} Two mutable objects with the same state differ. Relational ignores this uniqueness, and must fabricate it with [[candidate key]]s but that is a poor practice unless this identifier exists in the real world. Identity is permanent in relational, but maybe transient in OO.
* '''Object identity'''{{snd}} Objects (other than immutable ones) are generally considered to have a unique identity; two objects which happen to have the same state at a given point in time are not considered to be identical. Relations, on the other hand, have no inherent concept of this kind of identity. That said, it is a common practice to fabricate "identity" for records in a database through use of globally unique [[candidate key]]s; though many consider this a poor practice for any database record which 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 external world for identification purposes). Relational systems in practice strive for and support "permanent" and inspectable identification techniques, whereas object identification techniques tend to be transient or situational.
* '''Normalization'''{{snd}} OO neglects [[Database normalization|Relationalrelational normalization]] practices are often ignored by OO designs. However, this may just be a bad habit instead of a native feature of OO. An alternate view is that a collection of objects, interlinked via [[Pointer (computer programming)|pointers]] of some sort, is equivalentare toarguably a [[network database]];, which in turn can be viewedis asarguably an extremely denormalized [[relational database]].
* '''Schema inheritance'''{{snd}} Relational schemas reject OO's hierarchical inheritance. Relational accepts more powerful [[set theory]]. Unpopular non-tree (non-[[Java (language)|Java]]) OO exists, but is harder than relational algebra.
* '''Schema inheritance'''{{snd}} Most relational databases do not support schema inheritance. Although such a feature could be added in theory to reduce the conflict with OOP, relational proponents are less likely to believe in the utility of hierarchical taxonomies and sub-typing because they tend to view [[Set Theory|set-based]] taxonomies or classification systems as more powerful and flexible than trees. OO advocates point out that inheritance/subtyping models need not be limited to trees (though this is a limitation in many popular OO languages such as [[Java (language)|Java]]), but non-tree OO solutions are seen as more difficult to formulate than set-based variation-on-a-theme management techniques preferred by relational. At the least, they differ from techniques commonly used in relational algebra.
* '''Structure vs. behaviour'''{{snd}} OO primarily focuses on ensuring that the structure of the program is reasonable (maintainable, understandablemaintainability, extensibleextensibility, reusable, safe),. whereasRelational relational systems focusfocuses on what kind of behaviour the resulting run-time system hasbehavior (efficiency, adaptability, fault-tolerance, liveness, logical integrity, etc.). Object-oriented methods generally assume that the primary user of the object-orientedOO code andserves itsprogrammers, interfaces are the application developers. Inwhile relational systems,stresses the enduser-users'visible view of the behaviour of the system is sometimes considered to be more importantbehavior. However, relationalit queriescould andbe "views" are common techniques to present informationnon-inherent in application-relational, oras task-specific configurations.views Further,commonly relationalpresent doesinformation not prohibit local or application-specific structures or tables from beingto createdsubtasks, althoughbut manyIDEs commonignore developmentthis toolsand do not directly provide such a feature, assumingassume objects will beare used instead. This makes it difficult to know whether the stated non-developer perspective of relational is inherent to relational, or merely a product of current practice and tool implementation assumptions.
* '''Set vs. graph relationships'''{{snd}} The relationship between different items (objects or records) tend to be handled differently between the paradigms. Relational relationships are usually based on idioms taken fromfollows [[set theory]], whilebut objectOO relationships lean toward idioms adopted fromfollows [[graph theory]] (including [[Tree (graph theory)|trees]]). While each can represent the same information as the otherequivalent, the approaches they provide to access and managemanagement informationparadigms differ.
 
As a result of the object–relational impedance mismatchTherefore, it is often argued by partisans on both sides of the debate thatargue the other's technology ought toshould be abandoned or reduced in scope.<ref name="RDMDBobjectmis">{{cite web| first = Ted| last=Neward | title = The Vietnam of Computer Science| date=2006-06-26|access-date=2010-06-02| publisher = Interoperability Happens| url=https://www.odbms.org/wp-content/uploads/2013/11/031.01-Neward-The-Vietnam-of-Computer-Science-June-2006.pdf}}</ref> Some databaseRDBMS advocatesDBAs vieweven traditionaladvocate "procedural" languages as more compatible with an RDBMS than manyover OO languages; or suggest that a less OO style ought to be used. (In particular, it is arguednamely that long-lived ___domain objects in application code oughtshould not to exist; any such objects that do exist should be created when a query is made and disposed of when a transaction or task isoutlive complete)transactions. Conversely, some OO advocatesretorts argue that more OO-friendly persistence mechanisms, such aswith [[OODBMS]], oughttechnology to be developed and used, and thatreplacing relational technology ought to be phased out. Many (if notHowever, most) programmers and DBAs hold neither of these viewpoints;abstain and view the object–relational impedance mismatch as just a mere fact of life that [[information technology]] has to deal withhurdle.
 
ItORMs issituationally also argued that the O/R mapping is paying off in some situations, but is probably oversold: it hasoffer advantages besides drawbacks. Skeptics pointcite out that it is worth to think carefully before using itdrawbacks, as it will addand little value inwhen someblindly casesapplied.<ref>{{cite book|title=J2EE Design and Development|url=https://archive.org/details/expertoneononej200rodj|url-access=registration|first=Rod|last=Johnson|publisher=Wrox Press|date=2002|page=[https://archive.org/details/expertoneononej200rodj/page/256 256]|isbn=9781861007841 }}</ref>
 
== See also ==
Line 126 ⟶ 127:
{{DEFAULTSORT:Object-relational impedance mismatch}}
[[Category:Object-oriented programming]]
[[Category:Object-relationalObject–relational mapping]]
[[Category:Relational model]]