Introduction to iBatis (MyBatis), An alternative to Hibernate and JDBC
Join the DZone community and get the full member experience.
Join For Freei started to write a new article series about ibatis / mybatis . this is the first article and it will walk you through what is ibatis / mybatis and why you should use it.
for those who does not know ibatis / mybatis yet, it is a persistence framework – an alternative to jdbc and hibernate , available for java and .net platforms. i’ve been working with it for almost two years, and i am enjoying it!
the first thing you may notice in this and following articles about ibatis/mybatis is that i am using both ibatis and mybatis terms. why? until june 2010, ibatis was under apache license and since then, the framework founders decided to move it to google code and they renamed it to mybatis. the framework is still the same though, it just has a different name now.
i gathered some resources, so i am just going to quote them:
what is mybatis/ibatis?
the mybatis data mapper
framework makes it easier to use a relational database with
object-oriented applications. mybatis couples objects with stored
procedures or sql statements using a xml descriptor. simplicity is the
biggest advantage of the mybatis data mapper over object relational
mapping tools.to use the mybatis data mapper, you rely on your own objects, xml, and
sql. there is little to learn that you don’t already know. with the
mybatis data mapper, you have the full power of both sql and stored
procedures at your fingertips.
(
www.mybatis.org
)
ibatis is based on the idea that there is value in relational databases and sql, and that it is a good idea to embrace the industrywide investment in sql. we have experiences whereby the database and even the sql itself have outlived the application source code, and even multiple versions of the source code. in some cases we have seen that an application was rewritten in a different language, but the sql and database remained largely unchanged.
it is for such reasons that ibatis does not attempt to hide sql or avoid sql. it is a persistence layer framework that instead embraces sql by making it easier to work with and easier to integrate into modern object-oriented software. these days, there are rumors that databases and sql threaten our object models, but that does not have to be the case. ibatis can help to ensure that it is not.
( ibatis in action book)
so…
what is ibatis ?
- a jdbc framework
- developers write sql, ibatis executes it using jdbc.
- no more try/catch/finally/try/catch.
- an sql mapper
- automatically maps object properties to prepared statement parameters.
- automatically maps result sets to objects.
- support for getting rid of n+1 queries.
- a transaction manager
- ibatis will provide transaction management for database operations if no other transaction manager is available.
- ibatis will use external transaction management (spring, ejb cmt, etc.) if available.
- great integration with spring, but can also be used without spring (the spring folks were early supporters of ibatis).
what isn’t ibatis ?
- an orm
- does not generate sql
- does not have a proprietary query language
- does not know about object identity
- does not transparently persist objects
- does not build an object cache
essentially, ibatis is a very lightweight persistence solution that gives you most of the semantics of an o/r mapping toolkit, without all the drama. in other words ,ibatis strives to ease the development of data-driven applications by abstracting the low-level details involved in database communication (loading a database driver, obtaining and managing connections, managing transaction semantics, etc.), as well as providing higher-level orm capabilities (automated and configurable mapping of objects to sql calls, data type conversion management, support for static queries as well as dynamic queries based upon an object’s state, mapping of complex joins to complex object graphs, etc.). ibatis simply maps javabeans to sql statements using a very simple xml descriptor. simplicity is the key advantage of ibatis over other frameworks and object relational mapping tools.( http://www.developersbook.com )
who is using ibatis/mybatis?
see the list in this link: http://www.apachebookstore.com/confluence/oss/pages/viewpage.action?pageid=25
i think the biggest case is myspace , with millions of users. very nice!
this was just an introduction, so in next articles i will show how to create an application using ibatis/mybatis – step-by-step.
enjoy!
from http://loianegroner.com/2011/02/introduction-to-ibatis-mybatis-an-alternative-to-hibernate-and-jdbc/
Opinions expressed by DZone contributors are their own.
Comments