MyBatis development and selection

xlecho edited, welcome to reprint, please declare the source of the article. Welcome to add echo micro letter (Micro Signal: t2421499075) the exchange of learning. Battle undefeated, according to not claiming victorious, defeat after defeat is not decadent, according to energy struggling to move forward. - This is the real rated power! !


Reference list of articles:

The history of the data layer framework

The development of several major issues such as JDBC coding and MyBatis framework of support for the cause?
When originally written JDBC database connectivity, various code operation is more complex and has many defects. Defects are summarized as follows:

  • A method of packaging issues
  • Supported data sources
  • Mapping result set receiving and processing
  • Hard-coded SQL statements
  • Only the order of the incoming program parameters (placeholders)
  • Entity class does not implement the mapping database records
  • It does not provide caching and other functions

Appear tools package solves part of the problem

Appropriate tools such as: springjdbc, jdbcutils, Apache DbUtils like. Such tools mainly to solve a look at a few questions:

  • Encapsulation method
  • Supported data sources
  • Mapping result set

In response tools to achieve JDBC solve some shortcomings, but not perfect. Is the predecessor to improve the appearance of each of our framework and tools of the emergence of the framework is the tool. After the emergence of more and more perfect solution, ORM framework basically take shape. While addressing the various issues listed in the above JDBC.

Ying ORM framework, stands for Object Relational Mapping, object relationships

Object-oriented development approach is to mainstream development approach today's enterprise-class application development environment, a relational database is the main data storage system enterprise application environments permanent storage of data. Object and relational data are two forms of business entities in the form of business entity performance object in memory, the performance of relational data in the database. An association and inheritance relationships between objects in memory, and in the database, relational data can not be directly expressed many to many associations and inheritance. Accordingly, the object - relational mapping (ORM) system is generally present in the form of middleware, the main procedures for mapping objects to a relational database data.

ORM framework of the basic norms

  • A. simple: ORM most basic form modeling data. For example, a table MySQL will ORM mapped to a Java class (model), the table field is a member variable of the class
  • B. precise: ORM make all MySQL data tables are in accordance with uniform standards accurately mapped into java classes, allowing the system to maintain accurate unified code level
  • C. easy to understand: ORM make the database structure documentation. ORM such as MySQL database was converted to java programmers can read java class, java programmers can only focus on java level he is good (of course, to master MySQL better)
  • D. use: ORM containing API of the persistent object class CRUD operations, for example, create (), update (), save (), load (), find (), find_all (), where () and the like, that is speaking sql query functions all packaged in a programming language, resulting SQL statement generated by the chain of combinatorial functions. Through this package to avoid irregularities, redundancy, style is not reunification of SQL statements, you can avoid a lot of people Bug, convenient coding style uniform and ongoing maintenance.

The earliest hibernate ORM framework

Hibernate is an ORM framework, called Object_Relative DateBase-Mapping, to establish some kind of mapping between Java objects and relational databases to achieve direct access Java objects!

  • Hibernate advantage
    • Category to the database table, and without writing any code.
    • Provide simple APIs is stored directly in the database and retrieve Java objects.
    • If a change occurs or any other table in the database, then only need to change the XML file attributes.
    • Abstract unfamiliar with SQL type, and provides work in the familiar Java objects for us.
    • Hibernate does not require an application server to operate.
    • Manipulate complex objects in the database associated with you.
    • Strategies to minimize extraction and intelligent access to the database.
    • Provide simple data inquiry.
  • Hibernate response of some of the problems
    • Can not customize the SQL, optimization is relatively difficult
    • Dynamic braking is not SQL
    • The complex table relationships will lead to the development of Hibernate difficulty
    • Loading Problems

What is MyBatis?

It is a set of object-oriented relationship between the data and return the package layer, effectively reducing jdbc code.

  • Disadvantages:
    • Transplantation is not convenient, database fields need to be replaced too much trouble, we need to rewrite the sql
    • Written SQL developers rely on strong.
  • advantage:
    • Use connection pooling for connection management
    • SQL and code separation, centralized management
    • Parameter mapping and dynamic SQL
    • Result set mapping
    • Cache Management
    • Repeat SQL extraction
    • Plug-in mechanism
    • Handwriting sql, can effectively control the precise speed query, the query speed facilitates optimization
    • mybatis does not impose any impact on the existing application or database design
    • By providing DAO layer, the data access logic and business logic separated the clearer system design, easier to maintain, easier unit testing.
    • Guarantee the same name, automatically configured mapping relationship mapping or not configured mapping relationship, by configuring the column name = field names can also be done automatically mapped.

What is the Spring Data JPA (JPA paper write-only Spring Data JPA)

Spring Data JPA is part of a larger series of Spring Data can be easily JPA-based repository. This module handles enhanced support for data access layer based on the JPA. It allows drivers to build Spring applications using data access technology easier.

Choose what kind of ORM framework of reference:

  • Business is relatively simple project can use Hibernate
  • Need to be flexible SQL options can be used MyBatis (SQL is too long and complicated case SQL)
  • For high performance requirements can use JDBC (such as: We wrote the project is small, or that is the need for several interfaces, this time we choose framework would be too cumbersome and complicated)
  • Sping JDBC and ORM framework can mix (which is rare, but if some services may require a separate interface to a data source abutment, this time may be an adapter compatible access JDBC)

    To be a bottom line of the main blog

Guess you like

Origin www.cnblogs.com/xlecho/p/11521653.html