- 1. Why Mybatis?
2. Spring MyBatis interaction
- 2.1. What is MyBatis-Spring?
- 2.2. Installation
- 2.3. Spring application context setup
- 2.4. Injecting Mappers
- 2.5. MyBatis configuration XML
- 2.6. Mapper XML Files
- 3. Summary
- 4. Resources
1. Why Mybatis?
Short answer: simple, lightweight, open source, dynamic sql and sql control, previous iBATIS knowledge. Now let me elaborate a little bit on the subject. Back in the old days of Podcastmania.ro, see Story of Podcastpedia.org, I used my own MVC like framwork based on servlets to develop the web application and plain old JDBC to access the database. After “upgrading” to Spring MVC, I started using Spring’s
JdbcTemplate for database access, which removed some of the boilerplate code. Later I got involved in projects where database access occured via iBATIS – Hibernate was there for a long time, but because of legacy reasons and no database normalization whatsoever, iBATIS was the optimal choice. By about the same time MyBatis had been just launched, so I read the documentation, did a pilot, liked it and switched from Spring’s
JdbcTemplate to MyBatis. In the mean time I’ve been working on projects with Hibernate and JPA 2.0 with Hibernate used for persistence, so I’d say I have a pretty good overview on the most popular Java Persistence Frameworks. You have currently four major options:
- myBatis (former iBatis)
- Spring JDBC
Source code for this post is available on Github - podcastpedia.org is an open source project.