The work of the data Persistence layer is 1) to generate the required Java objects from the data queried from the database, and 2) to persist the data in the Java object to the database through SQL.
MyBatis by abstracting the underlying JDBC code, the process of automating the SQL result set to produce data persisted in Java objects and Java objects makes it easy to use SQL.
MyBatis abstracts These same tasks, such as preparing SQL statement objects that need to be executed and passing Java objects as input data to statement objects, so developers can focus on what really matters.
MyBatis automates the process of setting properties from input Java objects to query parameters and generating Java objects from the SQL result set.
MyBatis also provides additional features to simplify the implementation of persistent logic:
? It supports complex SQL result set data mapping to nested object graph structures
? It supports mapping of one-to-one and one-to-many result sets and Java objects
? It supports building dynamic SQL statements based on input data.
MyBatis is the mapping of the results of a query to a Java object, which allows MyBatis to work well with traditional databases. You can create Java domain objects based on an object-oriented model, execute queries from traditional databases, and then map the results to the corresponding Java objects.
The MyBatis has a built-in sqlsession level caching mechanism for caching the results of a Select statement query. In addition, MyBatis provides integrated support for a variety of third-party cache class libraries, such as Ehcache,oscache,hazelcast.
Performance issues are one of the key factors in the success of software applications. In order to achieve better performance, there are many things to consider, and for many applications, the data persistence layer is the key to the performance of the whole system.
MyBatis supports database connection pooling, eliminating the overhead of creating a single database connection for each request MyBatis provides a built-in caching mechanism that provides a cache of SQL query results at the sqlsession level. That is: If you call the same select query, MyBatis will return the cached results instead of querying the database.
The MyBatis framework does not use proxy mechanism 2 extensively, so MyBatis can achieve better performance for other ORM frameworks that use proxies excessively.
Each thread should have its own sqlsession instance. Sqlsession object instances are not thread-safe and are not shared. So the scope of the sqlsession is preferably the scope of the method in which it resides. From a WEB application perspective, sqlsession should exist at the request level scope.
Java Persistence with MyBatis summary 1