views:

246

answers:

3

For our new product re-engineering, we are in the process of selecting the best framework from Java. As the consideration is to go for database agnostic approach for model, we are working on options between Struts + Spring with iBATIS or Hibernate. Please advice which is best as both offer persistence.

+11  A: 

Ibatis and Hibernate are quite different beasts.

The way I tend to look at it is this: Hibernate works better if your view is more object-centric. If however you view is more database-centric then Ibatis is a much stronger choice.

If you're in complete control of your schema and you don't have an extremely high throughput requirement then Hibernate can work quite well. The object model makes for fairly convenient code but at a huge complexity cost.

If you're dealing with a "legacy" database schema where you need to write fairly complicated SQL queries then chances are Ibatis will work better.

HQL (Hibernate Query Language) is another language you'll have to learn and even then you'll probably find cases where you still need to write SQL. What's more, chances are you will at some spend half a day figuring out the right combination of XML, properties, annotations, etc to get Hibernate to generate a performant SQL query.

There is no universal "A is better than B" answer for this question.

cletus
Good take on this. +1
Adeel Ansari
Unbiased,clear overview, +1 from me. =]
Narayan
+2  A: 

Cletus did a great job at summarizing this comparison. Hibernate works well when you control the data model and is more object-centric while iBATIS works well when you need to integrate with an existing database and is more data-centric.

Also I think that Hibernate has a bit more of learning curve. With iBATIS, it's pretty easy to know what is going on while more "magic" happens with Hibernate. In other words, newbies might find iBatis easier to use and to understand.

But I'm not saying that you should prefer iBatis, iBatis and Hibernate are just different as said above.

And by the way, if you go for Hibernate, maybe consider using standardized JPA and EJB 3.0 (JSR-220) object/relational mapping annotations provided by Hibernate Annotations.

Pascal Thivent
+1  A: 

if you're already using Spring, I would start with Spring JDBC rather than plunging right into Hibernate or iBatis. If you write your persistence tier in terms of interfaces, you should have no problem switching implementations after you've gotten Hibernate or iBatis under your belt.

There's no reason why it has to be an "all or none" decision. Use what's best for your situation.

duffymo
Spring JDBC is vastly inferior to Ibatis. For one thing you either have to write row mappers (tedious) or Spring's bean mapping is incredibly slow. That doesn't matter if you're binding a form in Spring MVC but it sure does if you're returning thousands of rows. I cut down execution timeon a query from 50+ seconds to <2 just by replacing Spring's bean mapping in Spring JDBC with an explicit row mapper but who wants to write those?
cletus