Object-relational mapping
Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in 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 create their own ORM tools.
Contents |
[edit] Overview
Data management tasks in object-oriented (OO) programming are typically implemented by manipulating objects that are almost always non-scalar values. For example, consider an address book entry that represents a single person along with zero or more phone numbers and zero or more addresses. This could be modeled in an object-oriented implementation by a "person object" with "slots" to hold the data that comprise the entry: the person's name, a list of phone numbers, and a list of addresses. The list of phone numbers would itself contain "phone number objects" and so on. The address book entry is treated as a single value by the programming language (it can be referenced by a single variable, for instance). Various methods can be associated with the object, such as a method to return the preferred phone number, the home address, and so on.
However, many popular database products such as structured query language database management systems (SQL DBMS) can only store and manipulate scalar values such as integers and strings organized within normalized tables. The programmer must either convert the object values into groups of simpler values for storage in the database (and convert them back upon retrieval), or only use simple scalar values within the program. Object-relational mapping is used to implement the first approach.
The heart of the problem is translating those objects to forms that can be stored in the database for easy retrieval, while preserving the properties of the objects and their relationships; these objects are then said to be persistent.
[edit] Pros and cons
ORM often reduces the amount of code needed to be written[1].
Most O/R mapping tools do not perform well during bulk deletions of data and particularly complex or even simple joins. Stored procedures may have better performance, but are not portable. In addition, heavy reliance on ORM software has been pointed to as a major factor in producing poorly designed databases.[2]
[edit] Non-SQL databases
Another solution is to use an object-oriented database management system (OODBMS) or document-oriented databases such as native XML databases. OODBMS systems are databases designed specifically for working with object-oriented values. Using an OODBMS eliminates the need for converting data to and from its SQL form, as the data is stored in its original object representation and relationships are directly represented, rather than requiring join tables/operations.
Document oriented databases also prevent the user from having to "shred" objects into row of tables. Many of these systems also support the XQuery query language for fast retrieval of large datasets.
Object-oriented databases tend to be used in complex, niche applications. One of the arguments against using an OODBMS is that switching from an SQL DBMS to a purely object-oriented DBMS means that you may lose the capability to create application independent queries for retrieving ad-hoc combinations of data without restriction to access path. For this reason, many programmers find themselves more at home with an object-SQL mapping system, even though most commercial object-oriented databases are able to process SQL queries to a limited extent. Some OODBMS products support full ANSI SQL. [3]
[edit] See also
- List of object-relational mapping software
- AutoFetch - automatic query tuning
- CORBA
- Database
- Object database
- Object persistence
- Object-relational database
- Object-relational impedance mismatch
- Relational model
- SQL
- Java Data Objects
- Service Data Objects
[edit] References
- ^ Douglas Barry, Torsten Stanienda, "Solving the Java Object Storage Problem," Computer, vol. 31, no. 11, pp. 33-40, Nov. 1998, http://www2.computer.org/portal/web/csdl/doi/10.1109/2.730734, Excerpt at http://www.service-architecture.com/object-relational-mapping/articles/transparent_persistence_vs_jdbc_call-level_interface.html. Lines of code using O/R are only a fraction of those needed for a call-level interface (1:4). For this exercise, 496 lines of code were needed using the ODMG Java Binding compared to 1,923 lines of code using JDBC.
- ^ Josh Berkus, "Wrecking Your Database", Computer, Aug. 2009, http://it.toolbox.com/blogs/database-soup/wrecking-your-database-33298, Webcast at http://www.youtube.com/watch?v=uFLRc6y_O3s
- ^ Objectivity/SQL++ - an ANSI SQL interface to an OODBMS.
| This article needs additional citations for verification. Please help improve this article by adding reliable references. Unsourced material may be challenged and removed. (May 2009) |
[edit] External links
- About ORM by Anders Hejlsberg
- Mapping Objects to Relational Databases: O/R Mapping In Detail by Scott W. Ambler
- Core J2EE Design Pattern: Data Access Objects
- Choosing an Object-Relational mapping tool
- Why use an Object-Relational mapping tool
- Perl's DBIx::Class ORM
- Object-relational mappers for Python
- A tutorial with video explaining ORM
- QuickDB
- Simplest ORM
- nHydrate Model Driven Architecture
- O/R Broker