Content deleted Content added
Tag: Reverted |
m Disambiguating links to Object-orientation (link changed to Object-oriented programming) using DisamAssist. |
||
(43 intermediate revisions by 34 users not shown) | |||
Line 1:
{{Distinguish|Object-role modeling}}▼
{{Use dmy dates|date=June 2019}}▼
{{Refimprove|date=May 2009}}▼
{{short description|Programming technique}}
'''Object–relational mapping''' ('''ORM''', '''O/RM''', and '''O/R mapping tool''') in [[computer science]] is a [[Computer programming|programming]] technique for converting data between incompatible [[type system]]s using [[object-oriented]] programming languages. This creates, in effect, a "virtual [[object database]]" that can be used from within the programming language. There are both free and commercial packages available that perform object–relational mapping, although some programmers opt to construct their own ORM tools.▼
▲{{Use dmy dates|date=June 2019}}
▲'''Object–relational mapping''' ('''ORM''', '''O/RM''', and '''O/R mapping tool''') in [[computer science]] is a [[Computer programming|programming]] technique for converting data between
In [[object-oriented programming]], [[data management|data-management]] tasks act on [[object (computer science)|object]]s that
By contrast, relational databases, such as [[SQL]], group scalars into [[tuples]], which are then enumerated in [[Table (database)|tables]]. Tuples and objects have some general similarity, in that they are both ways to collect values into named fields such that the whole collection can be manipulated as a single compound entity. They have many differences, though, in particular: lifecycle management (row insertion and deletion, versus [[Garbage collection (computer science)|garbage collection]] or [[reference counting]]), references to other entities (object references, versus foreign key references), and inheritance (non-existent in relational databases). As well, objects are managed on-heap and are under full control of a single process, while database tuples are shared and must incorporate locking, merging, and retry. Object–relational mapping provides automated support for mapping tuples to objects and back, while accounting for all of these differences.<ref name="hibernate-orm-overview">
{{cite web |title=What is Object/Relational Mapping? |url=http://www.hibernate.org/about/orm |access-date=27 January 2022 |work=Hibernate Overview |publisher=JBOSS Hibernate |language=en-US}}
</ref>
Line 30 ⟶ 24:
</syntaxhighlight>
In contrast, the following makes use of an ORM-job API
<syntaxhighlight lang="csharp">
Line 37 ⟶ 31:
</syntaxhighlight>
The case above makes use of an object representing the storage repository and methods of that object. Other frameworks might provide code as static methods, as in the example below, and yet other methods may not implement an object-oriented system at all. Often the choice of paradigm is made
<syntaxhighlight lang="csharp">
var person = Person.Get(10);
</syntaxhighlight>
==Comparison with traditional data access techniques==
Compared to traditional techniques of exchange between an object-oriented language and a relational database, ORM often reduces the amount of code that needs to be written.<ref>
Disadvantages of ORM tools generally stem from the high level of [[Database abstraction layer|abstraction]] obscuring what is actually happening in the implementation code.
==Object-oriented databases==
Line 64 ⟶ 52:
A variety of difficulties arise when considering how to match an object system to a relational database. These difficulties are referred to as the [[object–relational impedance mismatch]].<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>
An alternative to implementing ORM is use of the native procedural languages provided with every major database. These can be called from the client using SQL statements. The [[Data access object|Data Access Object]] (DAO) design pattern is used to abstract these statements and offer a lightweight object-oriented interface to the rest of the application.<ref>{{cite web |last=Feuerstein |first=Steven |author2=Bill Pribyl |date=September 1997 |title=Oracle PL/SQL Programming |url=http://docstore.mik.ua/orelly/oracle/prog2/ch18_05.htm |access-date=23 August 2011 |
ORMs are limited to their predefined functionality, which may not cover all edge cases or database features. They usually mitigate this limitation by providing users with an interface to write raw queries, such as Django ORM.<ref>{{Cite web |title=Performing raw SQL queries {{!}} Django documentation |url=https://docs.djangoproject.com/en/5.1/topics/db/sql/ |access-date=2024-09-08 |website=Django Project |language=en}}</ref>
== See also ==
*[[List of object–relational mapping software]]
*[[Comparison of object–relational mapping software]]
Line 77 ⟶ 67:
*[[Relational model]]
**[[SQL]] (Structured Query Language)
*[[Java Data Objects]] (JDO)
*[[Java Persistence API]] (JPA), now [[Jakarta Persistence]]
*[[Service Data Objects]]
*[[Entity Framework]]
Line 94 ⟶ 85:
{{DEFAULTSORT:Object-Relational Mapping}}
[[Category:
[[Category:Data mapping]]
[[Category:Articles with example C Sharp code]]
|