[ORM] A brief talk about the ORM underlying framework of C# and Java

Give yourself a goal and stick to it for a while, and you will always gain something and gain insights!
The National Day holiday is about to end. In my free time, I suddenly became interested in the origin of the word Ado.Net, and then I reviewed it. By the way, I also learned about the bottom layer of the ORM framework in Java. !

Insert image description here

1. What is ADO

ADO (ActiveX Data Objects) is not an ORM (Object Relational Mapping) framework, but a set of components and interfaces for accessing data.

ADO provides a way to access and manipulate databases in applications. It is a connection-oriented, component-based framework.

The ORM framework is a technology used to simplify database operations. It allows developers to operate the database in an object-oriented manner by mapping database tables and objects. Some common ORM frameworks include Entity Framework, Hibernate, etc.

2. Relationship between ADO.Net and ORM

ADO.Net for C# is an underlying technology framework for accessing and manipulating databases. It provides a set of classes and interfaces for connecting to databases, performing SQL queries and update operations, and handling reading and writing of data. ADO.Net is a connection-oriented, component-based framework that provides direct database access capabilities.

The ORM (Object Relational Mapping) framework is a high-level abstraction built on ADO.Net. It encapsulates the details of database access and provides an object-oriented approach to database operations. ORM frameworks simplify the writing and maintenance of database operations by mapping database tables into objects and query results into collections of objects.

In C#, there is a certain relationship between ADO.Net and the ORM framework. On the one hand, ORM frameworks usually use the underlying database connection and execution functions provided by ADO.Net to achieve access to the database. In the ORM framework, they will encapsulate and extend some classes and interfaces provided by ADO.Net to provide more convenient and advanced database operation functions. On the other hand, developers who require more direct and fine-grained control over database operations can still use ADO.Net's classes and interfaces directly.

In summary, ADO.Net is the underlying framework for directly accessing and operating databases, while the ORM framework is a high-level abstraction built on ADO.Net, providing a more convenient and object-oriented way to perform database operations. During development, you can choose to use ADO.Net or ORM framework according to specific needs and situations.

3. Common ORM frameworks

The following is a rough list of common ORM frameworks in C# and Java. Please tell me in the comment area which one you commonly use.

serial number Development language ORM framework Remark
1 C# Entity Framework(EF) EF is an ORM framework officially launched by Microsoft. It supports a variety of database providers and provides powerful object-relational mapping functions and LINQ query language support.
2 C# NHibernate NHibernate is a mature open source ORM framework, which is a ported version of Hibernate on the .NET platform. NHibernate supports a variety of databases, provides rich mapping configuration options, and has flexible query functions.
3 C# Dapper Dapper is a lightweight ORM framework developed by the StackExchange team. Compared to other ORM frameworks, Dapper is more performance-focused and provides a simple way to directly execute SQL queries and map the results into objects.
4 C# LLBLGen Pro LLBLGen Pro is a commercial-grade ORM framework that provides a wide range of features and tools for configuring and generating data access layer code. It supports multiple databases, as well as advanced data model customization and query capabilities.
5 C# SQLSugar SQLSugar is an ORM (Object Relational Mapping) tool based on the .Net platform to simplify database operations.
6 Java Hibernate It is an open source ORM framework known for its flexible mapping and database access capabilities. It supports mapping between relational databases and object-oriented data models and provides a rich query language (HQL) to retrieve data.
7 Java MyBatis It is a simple and easy-to-use persistence layer framework that maps Java objects to database tables through XML or annotations. Compared with Hibernate, MyBatis is more flexible and can directly write SQL statements, providing more fine-grained control.
8 Java JPA(Java Persistence API) JavaEE's persistence standard, which defines a set of ORM specifications to provide developers with a way to simplify database operations. Implementations of JPA include Hibernate, EclipseLink, etc.
9 Java Spring Data JPA It is a module provided by Spring Framework to simplify JPA development. By using the Repository interface, it greatly reduces the amount of code written in the data access layer and provides some convenient query methods.

4. C# underlying technology

The underlying technology of the C# ORM framework usually involves the following aspects:

4.1、ADO.Net

ORM frameworks typically use the underlying database connectivity and execution capabilities provided by ADO.Net. ADO.Net is a framework officially provided by Microsoft for accessing and operating relational databases. It provides a set of classes and interfaces for connecting to the database, performing SQL queries and update operations.

4.2. Database provider

The ORM framework requires a database provider to communicate with a specific database. A database provider is a layer used to interact with different databases. It encapsulates the details of the underlying database engine so that the framework can interact with different types of databases in a unified way.

4.3. Mapping engine

The ORM framework needs to map objects to database tables, convert data in the database into objects, and save object modifications back to the database. The mapping engine is responsible for processing the mapping relationship between objects and database tables. Metadata and configuration are usually used to define the correspondence between tables and objects.

4.4. Query language

ORM frameworks usually provide a query language that is more suitable for object-oriented programming for complex query operations. These query languages ​​can perform type checking at compile time and provide richer and more flexible query capabilities, such as LINQ (Language Integrated Query).

To sum up, the underlying technologies of the C# ORM framework involve ADO.Net, database providers, mapping engines and query languages. These technologies are used to achieve convenient and efficient access and operation of the database. Different ORM frameworks may differ in processing methods and implementation details, but they all develop and extend based on these basic technologies.

5. Java underlying technology

The underlying technology of the Java ORM framework usually involves the following aspects:

5.1、JDBC(Java Database Connectivity)

JDBC is a set of database access standards provided by Java that defines a set of APIs and protocols for communicating with relational databases. The ORM framework maps and interacts between Java objects and database tables through the API provided by JDBC.

5.2. Database connection pool

ORM frameworks usually use database connection pools to manage database connections. Database connection pooling is a technology that reuses database connections, improving application performance and resource utilization by reducing the overhead of frequently creating and closing database connections.

5.3, Reflection

ORM frameworks usually use reflection mechanisms to dynamically manipulate the properties and methods of Java objects. Reflection can obtain the class information of the object at runtime and operate through the properties and methods of the class, allowing the ORM framework to persist the object to the database or read the object from the database according to the defined mapping relationship.

5.4. Cache

To improve performance, ORM frameworks often use caching technology to store frequently accessed objects or query results. The ORM framework can use caching to reduce the number of interactions with the database and increase the speed of data reading.

5.5. Affairs management

The ORM framework needs to support the management of database transactions. Transactions are a mechanism used to ensure the consistency and isolation of database operations. ORM frameworks usually provide transaction management functions, such as managing the start, commit, or rollback of transactions through annotations or declarative methods.

To sum up, the underlying technology of the Java ORM framework mainly includes JDBC as the interface for interacting with the database, and technologies such as database connection pooling, reflection, caching and transaction management to provide efficient object-relational mapping and database operation functions.

Guess you like

Origin blog.csdn.net/lmy_520/article/details/133604902