Friday, December 27, 2013

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.
share|improve this question
add comment

4 Answers

up vote74down voteaccepted
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.
share|improve this answer
 
Good take on this. +1 –  Adeel Ansari Dec 31 '09 at 9:46
 
Unbiased,clear overview, +1 from me. =] –  Narayan Jan 1 '10 at 8:39
 
For a lightweight and tiny ORM with SQL builder check MentaBean: mentabean.soliveirajr.com – TraderJoeChicago Sep 8 '11 at 16:26
3 
Now 2 years later, is this still true with the advent of jpa, hibernate has changed quite a bit and ibatis is now mybatis, im wondering what current thoughts of people out there are. –  Joelio Jan 5 '12 at 14:47
 
neatly written.. –  chaosguru Jun 24 '12 at 10:23 
show 2 more comments
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.
share|improve this answer
add comment
Consider what you're trying to achieve. Typically, the Command Query Response Segregation model works well for complex domains.
The reason is that you're trying to do one of two things typically:
  1. Create/Update/Delete some complex domain entities
  2. Run analytic fetch queries (i.e. summation/aggregation queries)
Hibernate works well for case 1 allowing you to just make a POJO and persist/update it. It also does this quickly, unless your domain is quite large.
myBatis is great for fetch queries (case 2) where you just want an answer. Hibernate would attempt to load the entire object graph and you'd need to start tuning queries with LazyLoading tricks to keep it working on a large domain. Conversely if you just want some analytic POJO page, the myBatis implementation of the same query would be trivial.
Because of this, myBatis is faster than Hibernate at SELECTS.
These two cases are the difference between Commands where you want to change the domain data and Responses where you just want to fetch some data.
So, consider these two cases and what your application does. If you have a simple domain and just fetch information, use myBatis. If you have a complex domain and persist entities, use Hibernate. If you do both, consider a hybrid approach. That's what we use on our project that has thousands of entities to keep it under control. ;)
share|improve this answer
add comment

No comments: