Share on Facebook Share on Twitter Email
Answers.com

Object-relational mapping

 

(Object-Relational Mapping) Converting data from tables in a relational database to objects and vice versa. Many applications employ object-oriented programming, but keep the data in traditional relational tables. The O-R mapping function can be accomplished with statements in the object-oriented programming language or via a third-party O-R mapping program.

For Complex Relationships

When an object model is very complex with a large number of many-to-many relationships, it takes time to store the data in relational tables. This "impedance mismatch" is resolved with the use of an object database, which is designed for complex object data. See object database and object-oriented programming.

Object Relational Mapping
There are three common types of O-R mapping from tables to objects and back again. A third-party O-R mapping program eliminates much of the tedium of writing this conversion code. (Illustration courtesy of the Real Time Division of Progress Software, www.progress.com/realtime)

Download Computer Desktop Encyclopedia to your iPhone/iTouch

Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Wikipedia: Object-relational mapping
Top

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 relational databases and 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

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.

Pros and cons

ORM often reduces the amount of code needed to be written,[1] making the software more robust (the fewer the lines of code in a program, the fewer the errors contained within them).

There are cons as well as benefits for using O/R mapping. For instance, some O/R mapping tools do not perform well during bulk deletions of data. Stored procedures may have better performance but are not portable.

Non-SQL databases

Another solution is to use an object-oriented database management system (OODBMS), which, as the name implies, is a database 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.

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 SQL queries, a tried and tested method for retrieving ad-hoc combinations of data. 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. [2]

See also

References

  1. ^ 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.
  2. ^ Objectivity/SQL++ - an ANSI SQL interface to an OODBMS.

External links


 
 

 

Copyrights:

Computer Desktop Encyclopedia. THIS COPYRIGHTED DEFINITION IS FOR PERSONAL USE ONLY.
All other reproduction is strictly prohibited without permission from the publisher.
© 1981-2009 Computer Language Company Inc.  All rights reserved.  Read more
Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Object-relational mapping" Read more