Hibernate and iBatis both are open source Object Relational Mapping (ORM) tools available in the industry. Both of these tools are very powerful and use of each of these depends on the context. Below are few criteria we can keep in our mind while choosing one over other.
Within the java persistence there is no one size, fits all solution. Hibernate is most commonly used ORM tool.
1. Way of working
Hibernate maps your Java based POJO objects to corresponding Database tables where as iBatis maps the ResultSet from JDBC API to Java POJO Objets. So in case of iBatis you may need to pass your parameters to the DAO class in a map object which can be passed to the Statement.
2. XML mappings
Hibernate and iBatis both use XML based mapping and are quite intuitive to implement. Tools are available to create and edit these file. e.g. Abator for iBatis and Hibernate tools.
3. Project from Scratch with new Database or Existing Database
Hibernate works well when you control the data model, iBATIS works well when you need to integrate with an existing database. In the projects where the Project is being developed from scratch and developer has to come up with database design along with the Java object model then Hibernate is a good option as it becomes easy to develop and mappings becomes intuitive. Hibernate also provides ways to generate database from mappings files itself. Which may reduce your deployment script generation efforts.
Using iBatis for a project which is developed from scratch is also very simple and does not involve lot of efforts.
4. Data centric project
A project that needs database intensive operations and needs to use lot of existing implementations that are available in Database side then iBatis provides simple ways to leverage it. Hibernate also provides way to handle such situations but it gets complex as your application becomes more and more complex. The hibernate developer need to start understanding lot of complex things to accomplish it.
5. Hibernate Query Language (HQL) vs Structured Query Language (SQL)
Its another choice which you may want to take in case you application involves lot of complex database intensive operations then in Hibernate you may want to go for Hibernate Query Language (HQL) which will have following aspects
- – Learning curve for developers
- – You will not be able to see the actual SQL because Hibernate generates it internally, though there is a way to see what is being generated but you lose the direct control over it.
- – Abstraction of SQL makes it difficult for the developers visualize what is happening at that layer.
Where as in case of iBatis you have same SQL available to you in the XML mapping file and you can play around with it as you wish, which gives you lot of freedom to tune in performance of queries.
6. Simple Applications
In case your application is simple with not lot of complex data processing then Hibernate could be a decent option. Also if a developer does not like SQL much then it could be a good option too.
7. SPRING Integration
Hibernate and iBatis both have good support from SPRING framework so it should not be a problem to chose one of them.