Hibernate vs. iBatis

I am currently working on a new project. This project is being done in Java and needs to access an RDBMS.

I started off using Hibernate, which has a fairly steep learning curve, and about 40% of the way through I decided to switch to iBatis.

First the reason why I switched. I found that while Hibernate could do simple things well, complicated things were much harder for some reason. I think this is mostly due to the lack of good examples in the documentation. The documentation presents lots of information on the various XML constructs, but does not do a good job of putting them in context with good examples. Building the XML file became an exercise in frustration trying to get things to work.

Still I was able to draw some interesting comparisons between the two.

Hibernate is a very abstracted layer, effectively shielding you completely from the underlying RDBMS. It generated all the SQL for you, both when you need to instantiate objects and when you need to run a query (it uses it own HQL to shield you from the native SQL supported by the RDBMS). It manages all the relations between objects, automatic updates, etc… All this abstraction comes at a price of course.

iBatis on the other hand is much closer to the metal. You have to write your own SQL (so are free to use as much or as little of the underlying RDBMS features), and it provides fairly minimal support for handling relations between tables. And you have to do a fair amount of extra work to isolate your application from ‘knowing’ that it is dealing with an RDBMS.

I can’t say that one is better than the other, they are both good at what they do, and they each provide a different set of features. My take on it at this point would be to recommend using iBatis unless you need the extra features provided by Hibernate.

Advertisements

3 Responses to Hibernate vs. iBatis

  1. noel says:

    I don’t really understand the recent trend to use these DB abstraction layers that completely take you away from the SQL. I understand that noobs that don’t know SQL like it because it allows them to do things they couldn’t do otherwise, but they often end up doing it wrong, inefficiently, or both. I like writing SQL. I like taking advantage of built in functions, procedures, and distro specifics.

    I never understood the argument that you might end up switching to antoher rdms. I think I’ve seen that happen once. It wasn’t much work to switch from mySQL to postGres either with some sed commands.

  2. I think that OO and RDBMS are two concepts that don’t really mesh well together, hence the need to provide abstraction to meld the two. Hibernate takes the approach of making the OO side of things as pure and clean as possible, hence the need to abstract as much as possible. iBatis comes in at a lower level, so there is what I would call ‘abstraction leakage’. For example, you can choose to write an application in C and have very tight control over memory management, or you can choose to write it in Java which handles all that for you. The point is that abstraction gives you convenience over control, well more like a shift in control. This is not a bad thing.

    One thing that is interesting is that both Hibernate and iBatis give you access to the underlying SQL if you want, but with iBatis you need to write all your SQL whereas with Hibernate you have to choose to write your SQL.

    While I have not heard of projects shifting from one RDBMS to another, I have heard of projects needing to integrate data from different RDBMSs, and for that Hibernate works well.

  3. Pingback: Accessing databases from Java « François Schiettecatte’s Blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: