Object Relational Mapping (ORM) – A Technical Report

COIT13235 Enterprise Software Development

Object Relational Mismatch

Object Relational Mapping (ORM) can be defined as a technique in computer programming system that is implemented for connecting or mapping objects to the relational database. It resolves the data type mismatch issue between the Object Oriented Programmings (OOPs) and the relational database. It performs as a medium for the data conversion between object oriented programming languages and relational database (Correa, Wang and Zimanyi 2017). In Object Oriented Programming, data are saved in the form of objects, however in the database, data are saved in the form of simple values, therefore ORM acts as a tool for the conversion of these objects into simple values to store it in the database without losing its properties. The following paragraphs give an introduction about the problems of object relational mismatch. The report highlights the benefits and limitations of implementing object relational mapping. The report also gives a description about the technologies of the object relational mapping.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Object relational mismatch:

Object relational mismatch is described as a condition that arises during the mapping or conversion of a class or object into database tables or relational database. The object oriented programming languages and relational database have their own data types, therefore a mismatch in data types occur while mapping object values to the relational model. The data in Object Oriented Programming are stored in the form of non-scalar values, however the data in database tables are specific and scalar values, therefore there occurs a mismatch or trouble while converting the Object Oriented data into relational database. Therefore, Object relational mismatch can be considered as the problem that is encountered during using a relational database for storing a set of objects from a program or software written in Object Oriented Programming language. The different types of mismatch problems that occur during storing Object Oriented data into tabular relational database are discussed in the following paragraphs.

Granularity problem:

The problem of granularity arises when there are more or lesser classes in the model of objects than the tables of relational database (Chen 2015). The condition in which a set of objects of Object Oriented Program are required to be mapped into a relational database and there is a difference between the amount of objects in the object model and tables in the relational database table is known as the problem of granularity.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Issue of Inheritance mismatch:

The Object Oriented Programming languages have a fundamental concept known as inheritance or sub-types in which one class can acquire the property of other class. However, relational database system does not support anything similar to inheritance or sub-types. A problem arises while converting or mapping objects of an inherited program into relational database as there is no method to implement the concept of inheritance in relational database system and this problem is known as the inheritance mismatch issue.

Problems of Object Relational Mismatch

Identity mismatch:

The relational database model and object model have different concepts of identity. In the relational database, the identity of rows or database are expressed in the terms of primary key, however in object model, each object has unique identity. The same data will be stored in the different threads while mapping the data from the database to the object model. In that case, a question arises that which object will have the right data that should be persisted in the database.

Problem in Association:

In Object Oriented languages, associations are represented in the form of unidirectional references, however in relational database, associations are bidirectional by using foreign keys. The user needs to define the association twice in order to develop a bidirectional relation in Object Oriented languages.

Navigation problem:

The method of navigating data in Object Oriented Language is different from the way it is done in relational database. The user needs to walk through the object network in order to navigate from one association to other, however the user can navigate and access the data through Structured Query Language (SQL) by loading several entities using JOIN.

Object Relational Mapping minimizes the length of the program or code that is required for accessing and mapping data from relational database in comparison to the traditional technique of accessing data. Therefore, ORM can be helpful in reducing the effort required for the development of the code. In comparison to the traditional data access technique, ORM is more useful for the business centric applications that have complex data structures as it provides better cache management, concurrency control and generation of basic create, read, update and delete (CRUD) code. However, ORM fetches more amount of data than required and therefore it works slower than the traditional data access technique. Therefore, ORM is not suitable for the applications having a simple data structure.

Reduction of code:

The ORM tool reduces the amount of the code that the developer is required to write for the application. It reduces the time required by the programmer for development of the code as it automatically generates whole data access code according to the model given by the programmer.

Management of cache:

ORM reduces load of the database server by storing the entities on the cache memory. Therefore, it is useful for the applications having a complex data structure as it provides cache management.

Better application management:

The codes that are generated by ORM are tested in a well manner, therefore the developer does not need to test it extensively.

Benefits of Object Relational Mapping

The Object Relational Mapping is a tool that helps in mapping of objects into relational database, however it also has limitations and drawbacks. The code that the ORM generates is usually more complicated than the program or code that a developer will write. This is due to the reason that ORM tool is designed for handling a large variety of data access scenarios that is far more than the code that a single application ever requires. The code generated by ORM is slow as it fetches more data than needed.

Java Persistence API:

Java Persistence Application Programming Interface (JPA) is specification of java that is used for managing and converting data between objects or classes and relational database. In java industry, JPA is considered as the standard method for ORM. It helps the developer in mapping, storing, updating and retrieving data from Java objects to relational database. JPA is a specification and various implementation are available that includes Hibernate, Eclipse Link and Apache Open JPA. It is usually implemented to manipulate and access relational database from Java beans and Java Standard Edition (SE).

Language Integrated Query:

Language Integrated Query (LINQ) is a combination of several features and properties that introduced formal query capabilities to the various languages that include Visual Basic and C#. Several adaptable solutions have also been introduced by LINQ in order to fill the gap between relational data and objects. Therefore, it can be said that LINQ acts as a bridge that maps and manipulates the objects of any Object Oriented Programming into the relational database. It is a framework of Microsoft dot Net programming model that adds query capabilities to the dot Net programming languages. Expressive and shorter syntax are provided by these extensions in order to manipulate data.

Hibernate Object Relational Mapping:

Hibernate Object Relational Mapping is an ORM tool or medium for Java programming. It is an ORM framework that acts as a tool for mapping and manipulating objects or classes into relational database. It uses XML files for mapping object or classes to relational database, therefore the programmer does not require to write much code in order to persist the object. The significant feature or property of Hibernate is converting, mapping and manipulating from the object model to relational database and mapping data types of Java into Structured Query Language (SQL) data types.

The RedBeanPHP is an Object Relational Mapping software that is designed for boosting the productivity of the developer. It is distinct from other Object Relational Mapping systems as it does not require any configuration in YAML or XML. The database schema is adapted according to the needs of the code or program by RedBeanPHP. The creation of tables and columns are done on the fly without any mapping or upfront configuration. The columns to the table are automatically added by RedBean and the type of the columns are changed according to the requirement of the content. It allows the developer to freeze the schema to prevent it from any further changes after all the required modifications are done.

Conclusion:

It can be concluded from the above discussion that the Object Relational Mapping is a useful tool for mapping and manipulating object or classes from an Object Oriented language to relational database. It acts as a medium for resolving the mismatch issues between the Object Oriented Programs and relational database or tables. There are several mismatch problems that arise during the conversion of object or classes to values in the database. There is a huge difference between the mapping through ORM tool and traditional data access technique. The ORM reduces the length of the code reducing the effort required for the development of the code. There are various advantages of implementing ORM technique for conversion of data, however it also has some limitations and drawbacks.

References:

Correa, B.B., Wang, Y. and Zimanyi, E., 2017. Object-relational mapping tools and Hibernate.

Chen, T.H., 2015, April. Improving the quality of large-scale database-centric software systems by analyzing database access code. In Data Engineering Workshops (ICDEW), 2015 31st IEEE International Conference on (pp. 245-249). IEEE.