ORM framework use and advantages and disadvantages

1. What is ORM?

Object-Relational Mapping (ORM), the object-oriented development method is the mainstream development method in today's enterprise-level application development environment, and the relational database is the mainstream data storage system for permanently storing data in the enterprise-level application environment. Objects and relational data are two representations of business entities. Business entities are represented as objects in memory and relational data in the database. There are associations and inheritance relationships between objects in memory, while in the database, relational data cannot directly express many-to-many associations and inheritance relationships. Therefore, the object-relational mapping (ORM) system generally exists in the form of middleware, which mainly realizes the mapping of program objects to relational database data.

2. Why use ORM?

When we implement an application (without using O/R Mapping), we may write code with a lot of data access layers to save, delete, and read object information from the database, and these codes are all repeated. Using an ORM will greatly reduce repetitive code. Object Relational Mapping (ORM) mainly realizes the mapping of program objects to relational database data.

3. Object-relational mapping explained:

A. Simple: ORMs model data in its most basic form. For example, ORM will map a MySQL table into a Java class (model), and the field of the table is the member variable 
B of this class. Precise: ORM makes all MySQL data tables accurately map to Java classes according to a unified standard, Keep the system accurate and unified at the code level 
. C. Easy to understand: ORM documents the database structure. For example, the MySQL database is converted by ORM into java classes that java programmers can understand. Java programmers can only focus on the java level that he is good at (of course, it is better to be proficient in MySQL) 
D. Ease of use: ORM contains the right APIs for CRUD operations on persistent objects, such as create(), update(), save(), load(), find(), find_all(), where(), etc., that is, SQL queries are all encapsulated into programming languages The function in , generates the final SQL statement through the chained combination of functions. This encapsulation avoids non-standard, redundant, and inconsistent SQL statements, avoids many human-made bugs, and facilitates the unification and later maintenance of coding styles. 
write picture description here

4. Advantages and disadvantages of ORM:

Advantages: 
1) Improve development efficiency and reduce development costs 
2) Make development more object-oriented 
3) Portable 
4) Additional functions such as data caching can be easily introduced 
Disadvantages: 
1) Automated mapping of relational databases requires system performance . In fact, the performance consumption here is okay, generally speaking, it can be ignored. 
2) When dealing with queries such as multi-table join queries and complex where conditions, the ORM syntax will become complicated.


5. Common frameworks:

(1) Hibernate automatically needs to write hql statements
(2) iBATIS semi-automatically writes sql statements by itself, which is highly maneuverable and compact

Guess you like

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