MyBatis

MyBatis (formerly iBATIS composed of "internet" and English abatis, mess ' ) is an open source persistence framework for Java and. NET. For Ruby and Ruby on Rails a ported version called RBatis is available.

The main task of MyBatis is the separation of database access code from the rest of the application code. For the application Data Access Objects are (short DAOs ) provided and the SQL statements in XML files, called SQL Maps outsourced. Thus, the allocation of tables to classes of the business logic is decoupled.

MyBatis is not an Object-Relational Mapping Framework (in short ORM), the mapping between object-oriented classes and relational tables must be done by the developers themselves, as well as writing the SQL statements for queries. Thus, the automatic creation of a database schema from the class hierarchy is not possible.

History

The iBATIS Project was founded by Clinton Begin in 2001. The original goal of the project was the development of cryptographic software, which is also crucial responsible for the part of " batis " in the project name (" batis " stands for " abatis " - engl for " mess ", a military defense system. ). The first completed by MyBatis software was "Secrets", an open -source encryption and Signierungstool in Java.

Beginning of 2002 appeared a Microsoft article claiming. NET would be 10 times faster and 4 times more productive than J2EE. This prompted the iBATIS project the sample application " JPetStore " ( first version July 1, 2002 ) to write and thus to refute the claims of the article. The Persistenzlayer used in this case, the SQL Maps and Data Access Objects, attracted the attention of the open source community. This resulted in the iBATIS framework, which simply represents the combination of the two parts.

During the year 2010 iBATIS moved by the Apache Software Foundation by Google code to. This move was based on the availability of new technologies in the field of social networks, version management and open source infrastructure. It also iBATIS was renamed MyBatis. The project is however still under the Apache license.

Today MyBatis is only the persistence framework, further comprising the two main components of SQL Maps and Data Access Objects. JPetStore acts as the official example of the typical use of MyBatis.

The framework is currently available in different versions for the programming languages ​​Java and. NET. Ruby has a port called RBatis. The jBati project, an ORM mapper for JavaScript inspired by MyBatis. The Apache project iBator provides a tool for MyBatis - it generated from databases the iBATIS mapping files.

Functionality

The main functionality of MyBatis is the separation of database access code from the rest of the application code. The main components of this are the Data Access Objects over which the application communicates with the Persistenzlayer, as well as the SQL Maps, which decouple the database access.

Like most persistence frameworks still offers a number of MyBatis beyond the mere persistence beyond features. These are such as support for transactions, both local and global (that is, database- border) on JTA and various performance optimizations such as lazy loading, join fetching or caching.

MyBatis generator

MyBatis includes a code generator " MyBatis Generator". MyBatis Generator queries the database tables and generates " MyBatis artifacts" which CRUD operations (Create, Retrieve, Update, Delete ) can be performed.

An Eclipse plugin is available.

Example

Let there be given a CUSTOMER table that has been created with the following SQL statement:

CREATE TABLE CUSTOMER (    K_ID INTEGER NOT NULL PRIMARY KEY,    K_NAME VARCHAR ( 128),    K_STR VARCHAR ( 128),    K_ORT VARCHAR ( 128),    K_PLZ INTEGER) Furthermore, there's the following POJO:

Package example;   public class Customer {    private int id;    private String name;    private String location;    private String street;    private int plz;      Follow / / getter and setter methods } To run a query, an XML descriptor file must be present:

de