1. What is ORM?
Object-Relational mapping (object-relational Mapping, or ORM), object-oriented development method is the mainstream development method in enterprise application development environment, and relational database is the main data storage system for permanent data storing in enterprise application environment. object and relational data are two representations of business entities, and business entities are represented as objects in memory, and relational data are represented in the database. There is an association and inheritance relationship between objects in memory, and in a database, relational data cannot directly express Many-to-many associations and inheritance relationships. Therefore, object-relational mapping (ORM) systems generally exist in the form of middleware, which mainly implements the mapping of program objects to relational database data.
2. Why use ORM?
When we implement an application (without the O/R Mapping), we may write code for a particular multiple data access layer, saving, deleting, and reading object information from the database, which is duplicated. Using ORM, however, greatly reduces the repetitive code. Object-Relational mapping (relational Mapping, or ORM), which mainly implements mapping of program objects to relational database data.
3. Object-Relational mapping explanation:
A. Simple: ORM models data in the most basic form. For example, ORM maps a table of MySQL to a Java Class (model), and the table field is the member variable of that class.
B. Precision: ORM enables all MySQL data tables to be accurately mapped into Java classes in accordance with uniform standards, keeping the system accurate and consistent at the code level
C. Understandable: ORM documents the database structure. For example, the MySQL database is ORM conversion for Java programmers can read Java classes, Java programmers can only focus on his good Java level (of course, can master MySQL better)
D. Ease of Use: ORM contains APIs that perform CRUD operations on persistent class objects, such as Create (), update (), save (), load (), find (), Find_all (), where (), and so on, That is, SQL queries are all encapsulated into functions in a programming language, generating the final SQL statement through a chain combination of functions. Through this encapsulation avoids the nonstandard, redundant, the style does not unify the SQL statement, may avoid many people for the bug, facilitates the coding style unification and the late maintenance.
4. ORM Advantages and Disadvantages:
Advantages:
1) Improve development efficiency and reduce development costs
2) Making development more object-oriented
3) Portable
4 can easily introduce additional functions such as data caching
Disadvantages:
1 Automated mapping of relational databases consumes system performance. In fact, the performance consumption here is OK, generally can be ignored.
2 The ORM syntax can be complicated when querying queries such as multiple table-checking, where conditions are complex.
5. Common frame:
(1) Hibernate fully automatic need to write HQL statements
(2) IBATIS semi-automatic write their own SQL statements, the operability of strong, compact