Snake

1. Introduction 
        to ORM Object Relational Mapping (ORM) mode is a technology to solve the mismatch between object-oriented and relational databases. Simply put, ORM automatically persists objects in a program to a relational database by using metadata that describes the mapping between objects and the database. So, how to achieve persistence? A simple solution is to hard-code a separate method for each possible database access operation. 
        This solution has the following shortcomings: 
        1. The persistence layer lacks elasticity. Once the business requirements change, the interface of the persistence layer must be modified. 
        2. The persistence layer is bound to the domain model and the relational database model at the same time. No matter whether the domain model or the relational database model changes, the poison modifies the relevant program code of persistence. , increasing the difficulty of software maintenance. 

        ORM provides another mode for implementing persistence layer, which uses mapping metadata to describe the object-relational mapping, so that ORM middleware can act as a bridge between the business logic layer and the database layer of any application. Java's typical ORM middleware are: Hibernate, ibatis, speedframework. 
        ORM's methodology is based on three core principles: 
  · Simplicity: Model data in its most basic form. 
  · Communicability: The database structure is documented in a language that anyone can understand. 
  · Accuracy: Create correctly standardized structures based on the data model. 

Second, the concept of ORM 
        Let's start with O/R. The letter O originates from "Object", while R comes from "Relational". Object and relational databases exist in almost all programs. In the business logic layer and the user interface layer, we are object oriented. When the object information changes, we need to save the object information in the relational database. 
        When you develop an application (without using O/R Mapping), you may write a lot of code in the data access layer to save, delete, read object information from the database, etc. You write a lot of methods in the DAL to read object data, change state objects, etc. And these codes are always repeated. 

        The main problem that ORM solves is object-relational mapping. The domain model and the relational model are based on the conceptual model, respectively. Domain model is object-oriented while relational model is relational. In general, a persistent class corresponds to a table, each instance of the class corresponds to a record in the table, and each attribute of the class corresponds to each field of the table. 
        ORM technical features: 
        1. Improve the development efficiency. Since ORM can automatically map fields and attributes between Entity objects and Tables in the database, we may actually no longer need a dedicated and huge data access layer. 
        2. ORM provides a mapping to the database, without direct coding of sql, and can obtain data from the database like an operation object. 

Third, the advantages and disadvantages of 
        ORM The disadvantage of ORM is that it will sacrifice the execution efficiency of the program and will fix the thinking mode. 
        From the point of view of system structure, the system using ORM is generally a multi-layer system. The more layers of the system, the lower the efficiency. ORM is a completely object-oriented approach, and object-oriented approach will also have a certain impact on performance. 

        As we develop systems, there are generally performance issues. Performance problems mainly arise from incorrect algorithms and incorrect use of databases. The code generated by ORM is generally unlikely to write very efficient algorithms, and it is more likely to be misused in database applications, mainly in the extraction of persistent objects and data processing. If ORM is used, Programmers are likely to extract all data into memory objects, and then filter and process them, which is prone to performance problems. 
        When persisting objects, ORMs generally persist all properties, and sometimes, this is not desired. 
        But ORM is a tool, and tools do solve some repetitive, simple labor. This is undeniable. But we can't expect tools to solve all problems once and for all. Some problems still need special treatment, but the parts that require special treatment should be very few for most systems.

 

 
 

   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325314551&siteId=291194637