In: Computer Science
Design and UI Patterns
Object models and relational models do not always work very well together. Databases represent data in a tabular form, whereas object-oriented languages represent data based on a graph of objects. There are a few common mismatch problems that can exist with association, aggregation, inheritance, and composition, and data navigation.
The Object-Relational Mapping (ORM) is the solution to handle all the above impedance mismatches.
What is ORM?
ORM stands for Object-Relational Mapping (ORM) is a programming technique for converting data between relational databases and object oriented programming languages such as Java, C#, etc.
An ORM system has the following advantages over plain JDBC −
| Sr.No. | Advantages |
|---|---|
| 1 | Let’s business code access objects rather than DB tables. |
| 2 | Hides details of SQL queries from OO logic. |
| 3 | Based on JDBC 'under the hood.' |
| 4 | No need to deal with the database implementation. |
| 5 | Entities based on business concepts rather than database structure. |
| 6 | Transaction management and automatic key generation. |
| 7 | Fast development of application. |
An ORM solution consists of the following four entities −
| Sr.No. | Solutions |
|---|---|
| 1 | An API to perform basic CRUD operations on objects of persistent classes. |
| 2 | A language or API to specify queries that refer to classes and properties of classes. |
| 3 | A configurable facility for specifying mapping metadata. |
| 4 | A technique to interact with transactional objects to perform dirty checking, lazy association fetching, and other optimization functions. |