Topic 11
■■■
Using MyBatis in Spring
In the previous three chapters, you saw how Spring supports seamless integration with different libraries
and techniques for implementing data access logic, from the traditional JDBC approach to ORM
solutions including Hibernate and the JEE standard JPA. In this chapter, we will discuss another popular
data access library: MyBatis (www.mybatis.org).
Formerly known as iBATIS (which was hosted on the Apache Software Foundation and was retired),
MyBatis is a Java library (a .NET version is also available) that provides a data mapper framework for
mapping the database relational structure into Java's OO model. However, instead of focusing on
programming to the OO model like ORM does, MyBatis is more focused on the SQL side. You can think
of MyBatis as the hybrid approach between JDBC and ORM. The MyBatis development team classifies
MyBatis as a SQL-based data mapping solution for object-oriented software development.
In this chapter, we are going to focus on implementing the data access layer of a Spring application
using MyBatis. Specifically, we will cover the following:
Configuration: We will discuss how to configure MyBatis with Spring, including
·
the Maven dependencies required and the configuration of MyBatis's
SqlSessionFactory in Spring's ApplicationContext.
MyBatis SQL mapping: In this section, you will learn how to define SQL mappings
·
with MyBatis for transforming the resultset of SQL queries into the properties of
the corresponding Java domain objects.
CRUD operations: You will learn how to implement select, update, and delete
·
operations using MyBatis. You will also learn how to implement select operations
that represent major types of data relationships.
Using MyBatis in the sample application: In the sample application, for the
·
MyBatis implementation, we will eliminate the DAO layer and have the MyBatis
mappers being directly injected into the service layer for executing business logic.
We will discuss how MyBatis will be adopted in the sample application.
Getting Started with MyBatis in Spring
In this section, we will cover how to set up MyBatis to work with Spring. First we will provide a brief
introduction to MyBatis, and then we will demonstrate how to create a project in STS for working with
MyBatis. Also, we will present the data model that will be used for implementing the samples in this
chapter. Finally, we will discuss the Spring configuration required for working with MyBatis.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home