Matt RaibleMatt Raible is a Java Champion and Developer Advocate at Okta. developer.okta.com

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Hibernate vs. iBATIS

There's an interesting thread taking place on the iBATIS User Mailing List. The basic jist of the responses are: Hibernate works well when you control the data model, iBATIS works well when you need to integrate with an existing database. I've said this for a couple years now, and I still believe it. Furthermore, I've found that when working with iBATIS, I tend to know what's going on a lot more. After all, it's just SQL. From all the questions on the AppFuse mailing list, it seems like a lot of Hibernate users are constantly trying to get Hibernate to "work its magic" and handle all their relationships for them.

I wonder if newbies would be better of using iBATIS? Using iBATIS, there isn't a whole lot of magic, and you get full control over the SQL - which would likely be easier to understand. Maybe I should create a "newbie" version of AppFuse - where the frameworks uses are the easiest to learn or most documented. It'd probably be Struts+Spring+iBATIS, or maybe just Spring+iBATIS so I could sell more copies of Spring Live. ;-)

Posted in Java at Feb 28 2005, 07:10:25 AM MST 38 Comments
Comments:

1. IMHO Hibernate would be much better with right tools that do all the magic. Just try Jetbrains VisualFabrique (there's a new EAP release). Their tool has an ER modeler that does all the "magic configuration" for Hibernate, so the user can concentrate on the business logic. Just look what does the tool generates :).
2. Regarding Spring Live: is there really and advantage for the autor to publish a book in "live mode", instead of the tradional one? (since only a few books use this strategy - compared to the high number of IT books)

Posted by Ahmed Mohombe on February 28, 2005 at 11:12 AM MST #

Ahmed, there is an absolute advantage to publishing a book in the "live mode", especially when dealing with the open source model. Let's look at Matt's book. In the next few months, Spring will release version 1.2. At that time, Matt will most likely make additions to "Spring Live" that will cover the new functionality and features. This would be near impossible with the traditional model.

With the "live mode", it seems to be the difference in writing solely history or history with current event updates.

Of course, I am *slightly* biased.

Cheers,
Matthew Porter

Posted by Matthew Porter on February 28, 2005 at 12:24 PM MST #

Yes, I do realize that in a "live book" one might add things - hence it's name, but I wanted to know if this approach has advantages/disadvantages(over the old model) for the author himself (not for the users who, of course, will always have the latest updates).

Posted by Ahmed Mohombe on February 28, 2005 at 12:31 PM MST #

Ahmed, If the user benefits from the 'live book' then it sells more copies which is the obvious 'advantage' to the author.

Posted by Wayland Chan on February 28, 2005 at 01:12 PM MST #

Hi Matt. I've worked with iBATIS and Hibernate for a while and have deplyoed iBATIS in my development team and it is really easy to get people excited about vs. Hibernate. All the 'magic' that's in Hibernate seems to scare people -- People are so happy that they can debug an application that's written using iBATIS as it's just SQL, XML and JavaBeans. I'll add my vote for a new AppFuse that's a Spring+iBATIS only -- I've directed a lot of people to AppFuse and Equinox as a starting point for Spring, iBATIS, etc.

Posted by Vinny Carpenter on February 28, 2005 at 08:17 PM MST #

Hibernate is another app that pertains to an argument I have with myself quite often. That is, how much do you need to be comfortable with what's going on before you can actually use the service. There has to be a point where you have to stop trying to figure everything out and start developing the application you're working on, no? I'm content with some of the Hibernate magic just as I'm content with using the STL when I'm coding C++ even if I'm not sure how they've implemented something that I'm using, because I know how to use it and it works, and isn't that the ultimate goal?

Posted by PJ Hyett on March 01, 2005 at 01:02 AM MST #

to Wayland:
What you said sounds like from some politician :), or some manager that don't wan't to rise my wage :).
to Vinny:
"People are so happy that they can debug an application". This is simply not true. People are so happy when they don't need to debug an application - they use unit tests (and test cases) to prevent it from the begining. Besides, if the application is so well designed like AppFuse, than you can separate your concerns, so only in extreme situations one realy needs to debug the application as an entire, and to step in every library.
I personally like all the magic from AppFuse/Hibernate/AppGen/middlegen/hibernate_synchronizer/etc. . Concentrating on the the essential in an application is really fun. If I would want to controll everything than I would end up with Assambler.

Why do ask so many people here about Hibernate?
Because Hibernate is bad? No! Most of the users get scared on the Hibernate forums and when they don't get the RTFM, than some half answer that mostly doesn't help a newbie. Matt on the other hand, explains everything so good that even newbies understand this - IMHO this is the key difference.

Posted by Ahmed Mohombe on March 01, 2005 at 04:41 AM MST #

Matt: I would vote for AppFuse examples using the minimum set of tools recommended to do the job. Part of the problem today is the complexity factor just in the number of entities, tools, one must learn to spell, learn and remain aware and competent using and applying such tools. It appears from the dialogue and comments elsewhere that a possible simple set of tools is formed by Spring and iBatis and welcome AppFuse example with just these tools. This set will make it a good one to introduce java-based programming to new developers. I started with jdbc, moved to Hibernate and over time discover iBatis which I find it a simpler and a better tool for my needs.

Posted by Jaime F. Zarama on March 01, 2005 at 09:22 AM MST #

We use ibatis for acessing stored procedures in the DB. This totally separates code from SQL. Maps is perfectly suited for this and it works like a charm with our home grown command pattern architecture. Hibernate is perfect i think for transparent persistence of objects, but not for data manipulation.

Posted by anon on March 01, 2005 at 09:53 AM MST #

When I first cracked the Spring examples, I went towards the iBatis implementations. My current client's project we're using Spring+Struts+Hibernate. The project I'm working on at home I'm using Spring+iBatis.
I personally like iBatis better due to my strength in SQL. Hibernate's abstraction of SQL doesn't allow me to truly understand what's happening. Plus the ability to write custom SQL in Hibernate buys very little for the complexity. I can appreciate those people who don't have a solid understanding of SQL and their use of Hibernate. I just find that level of abstraction unnecessary and more complex especially when something goes wrong.

Posted by Chris Rosenquest on March 01, 2005 at 03:44 PM MST #

I don't find Hibernate all that tough, and you can customize your queries with SQL. You do not have to use HQL. That said.... A fair bit of our business is helping people who make mistakes with Hibernate. Gavin wrote an article showing how to use Hiberante like you would iBatis. Didn't he? On most projects I've worked on recently, I've worked with Hibernate 90% to 97% for the persistence code. For the other 3 to 10 percent I used Spring JDBC or Apache DBUtils. I could have used iBatis for the remaining 3 to 10 percent. I have never used iBatis in production. I might use it in place of DBUtils in the future. How would you compare Spring JDBC (something I have used) to iBatis (something I have not used except to play around)?

Posted by Rick Hightower on March 01, 2005 at 06:26 PM MST #

+1 for iBatis, IMHO, iBatis is flexible, simple and clean vs hibernate, moreover I can get exactly what I want. Of course, when developing a simple CRUD application, hibernate has more productivities, although I think the maintaining tasks and performance tuning would be a headache.

Posted by 211.144.200.89 on March 01, 2005 at 08:27 PM MST #

How;s this: down the line (not today, not this week, not this month...), I think it would be great to have a basic "Equinox" or AppFuse integrating these tools: Tiles (if it goes standalone), JavaServer Faces, struts-menu, Struts "Shale" (if it really firms up, and if it provides something useful over and above JSF), Spring (especially Spring WebFlow), and iBATIS SQLMaps.

Posted by Christopher K Koenigsberg on March 03, 2005 at 11:53 AM MST #

I vote for iBatis + Struts + Spring DAO/Transaction. Keep it simple.

Posted by 204.114.53.254 on March 17, 2005 at 02:07 PM MST #

Is there any information/estiminates about the number of iBATIS developers?

Posted by PJ Murray on April 06, 2005 at 09:37 AM MDT #

It looks like there's currently 5 developers. They've also applied to become an Apache project.

Posted by Matt Raible on April 06, 2005 at 10:07 AM MDT #

I also vote for Ibatis - for simplicity and the fact that it is closer to the database. As I would vote for Tapestry v.JSF - as closer to html. I understand people who are always demand more abstraction, soemthing closer to perfection, but I now prefer to control my sql (or my xhtml/css) than having someone controlling it for me. It seems to me that one do not need abstracting the abstraction when the environement is well defined. I mean, when the environement can change (the database for Hibernate/the browser for jsf) these are good abstraction levels, but is it worth in 85% of the projects? Ibatis can have better performance and less pain when you try to integrate existing database. I tried Hibernate on a 20 years old database, with busines keys, it was not the right tool. You need to know sql, but anyway you always need to know sql, so what is the point? Hibernate is magic, Hibernate is fascinating. Ibatis is practical. Both are powerfull. But as with Tapestry v. jsf, the best solution is not always the one my boss or my clients think it is.

Posted by Gabriel on April 09, 2005 at 06:59 AM MDT #

iBATIS is good for basic or mapping, but it falls way short of hibernate in more complex orm. Hibernate has a lot built into that are intended to compete with EJB CMP not jdbc and iBATIS. If you are use to rolling your own persistence then iBATIS will seem amazing. Just wait for a cross cutting concern or a User Type to get you scratching your head. Oh, and how do you abstract anything with iBATIS? Oh yeah, and Hibernate now has filters. I guess what I am really saying is iBATIS is a good primitive tool, and good for introducing people to orm that haven't a clue. If you then have some mreo complex problems you should probably consider Hibernate. I can appreciate the above comments for why iBATIS is good, and don't necessarily disagree, but you will be limited at some point with it's simplicity. If it is all you need, happy birthday!

Posted by Adam Waldal on June 09, 2005 at 08:14 PM MDT #

Oh, one more thing for the life of god quit using or saying Struts is great as an MVC framework in the same sentence with good frameworks. People should start using good frameworks like Hibernate, Spring, iBATIS, . Struts does not belong in the same paragraph let alone sentence. Use Spring MVC, JSF, WebWork, Tapestry, pick one...drop Struts I am sick of looking at it! People will probably flame me for saying this of Struts, and it is everywhere, well it is time for a change! Struts is losing for god's sake give it a proper burial!

Posted by Adam Waldal on June 09, 2005 at 08:24 PM MDT #

hey, iam concerned in using spring with jsf and hibernate. is there a better alternative.

thanks

Posted by abdullah beik on September 27, 2005 at 11:44 PM MDT #

Abdullah - why are you concerned? I've used Spring with JSF and Hibernate in AppFuse and Equinox and it seems to work just fine. If you have any issues, it's likely to be with JSF's consumption of memory, not with Spring or Hibernate. And you'll likely only run into JSF issues under high load.

Posted by Matt Raible on October 04, 2005 at 12:58 PM MDT #

i want to use IBATIS with jsf. please give me note about this. is there any tutorial?

Posted by Jeeva on January 19, 2006 at 11:15 PM MST #

Jeeva - here's an article on creating a CRUD application with JSF.

Posted by Matt Raible on January 23, 2006 at 10:43 AM MST #

Pheeeew,

Here in my company, www.gamatechno.com, we are starting to use JEE as a production environment. But, because there are sooo many opts, three of us demonstrate the use of their options to implement some --very-- simple Guest Book application.

I opt to use Spring + Hibernate + Velocity (? .. JSF). But then again, after reading the opinions about iBatis, well, I was seduced (sad isn't it?).

Dear GOD, is there a way to make me confident of what I choose?

Well, I look at all the technologies use by www.alfresco.com, so... I opt that technologies too : Spring + Hibernate + JSF

So, Mr. Raible, ... can you ... well, help me????

With Regards,
Eko SW

P.S. : JSF Vs. Velocity/Freemarker , maybe I choose Velocity, because (they said) the separation of work between HTML Designer and JAVA programmer can be done easily.

Posted by swdev on August 08, 2006 at 04:35 AM MDT #

From personal experience, I'd recommend Spring MVC or WebWork (a.k.a. Struts 2) for your web framework. I've used these both and enjoyed using them. While I've implemented JSF and Tapestry in AppFuse, I don't feel I have enough real-world experience to recommend them.

Both Spring MVC and WebWork allow you to use JSP, Velocity or FreeMarker. I'd recommend using JSP unless you have a good reason not too. JSP 2.0 is a must.

Posted by Matt Raible on August 08, 2006 at 07:52 PM MDT #

Hi Matt,

I'm doing a very simple web project that needs to get off the ground quickly, it's a project where our team (3 developpers) have BASIC experience in HTML, JSP, and database experience. We want to get a look on some nice technologies, but don't necessarily have a lot of time for a steep learning curve. What would you suggest : Struts vs Spring, iBatis vs Hibernate. Our application has simple CRUD operations and simple page flow.

Thanks.
Pascal.

Posted by Pascal on October 27, 2006 at 10:57 AM MDT #

Pascal,

From the choices you've given, I'd recommend Spring MVC over Struts. As far as iBATIS vs. Hibernate - I think iBATIS is easier to learn, but I continue to choose Hibernate for most of the applications I write. Then again, I've been using Hibernate since 2003. ;-)

Posted by Matt Raible on October 29, 2006 at 02:33 PM MST #

Matt:

Long time no talk to...

I recently tried to use Hibernate as part of a new SOA architecture with a legacy model 1 JSP application. The legacy app had enormously long SQL statements and a very poor db schema. We ended up abandoning Hibernate. Ibatis made it easy for us to create CRUD DAOs and work with the existing schema mess. Creating dynamic finders were easy too. We're sold on Ibatis. It works really well with Spring.

I've heard Hibernate advocates claim you'll need hibernate for advanced use cases. I've not found that to be the case. I'm a big fan of KISS. Ibatis fits the bill. Hibernate is too complex and quirky. If you don't think so, read this page... http://hibernate.org/109.html From this URL it sounds like hibernate has not worked out some of the most basic persistence object identity issues. Problems like that make an application unstable at runtime, and are very difficult to solve.

If I was going to start a new app from scratch, and had the time to learn the "right way" to use Hibernate, I might take the plunge again. However, you've got to consider that others will follow in modifying your code, and they'll have to learn Hibernate too.

Another persistence framework to consider may be the one included with http://ofbiz.apache.org/ I don't think it's designed to be used stand-alone, but I think some projects have used it that way, notably Jira. It hides the underlying database the way Hibernate does, but it also adds db columns as needed.

I'd like to see a Java framework that dynamically builds CRUD (list and detail) as fast as plone/RoR/etc that includes security, optimistic locking, client-side validation, etc. I'm considering building a portlet for Liferay.com that allows you to build a CRUD portlet and edit it at runtime, adding table columns, etc.

Sorry for the long winded post. I've been thinking about this stuff a lot lately.

mike
Open Source Software Solutions

Posted by Mike Lawrence on January 29, 2007 at 08:21 PM MST #

Hi, I'm newbie with ibatis, I just want to test it for SOA implementation. Is there a basic tutorial for ibatis? thank you in advance. pobs

Posted by pobs on January 31, 2007 at 07:17 AM MST #

Struts/tapestry/JSF/etc. Has anynone tried wicket? We want to try it out, what I could gather from the web are good references, better than for any other UI framework for web-based apps, but I'd really like to hear some more opinions, from ppl who never used it before. br, flj

Posted by A_flj_ on April 13, 2007 at 12:15 AM MDT #

Hello Matt, Is there a code generator which generates the entire CRUD application using spring + spring MVC + ibatis. I am just tired of writing CRUD applications now and sincerely wish somebody created an online application which just took the DDL from my database schema and created application code based on selected technology stack... Cheers, Gaurav

Posted by Gaurav on May 10, 2007 at 03:51 PM MDT #

Gaurav - yes, AppFuse 1.9.4 will do this for you. AppFuse 2.x will do this in the next release, but currently it's code generation has only been tested with Hibernate.

Posted by Matt Raible on May 25, 2007 at 10:10 AM MDT #

Nice posting. I'm in the process of learning iBatis now as I have found Hibernate good to use, until something goes wrong. Then I'm on forums for hours trying to figure out what happened. I understand databases so I am hoping to get more mileage out of iBatis. Keep up the good work Matt, you have lots of fans out here. Luke

Posted by Luke on September 09, 2009 at 08:25 AM MDT #

Thanks for this great thread.

Just wondering in 2010 - Does the argument of this blog post still hold good in 2010 ?

Thanks

>>Hibernate works well when you control the data model, iBATIS works
>>well when you need to integrate with an existing database

Posted by Mathew on January 04, 2010 at 10:47 AM MST #

I don't know if anyone made some serious performance benchmarks...

I DID

Hibernate and Ibatis are pretty close when it comes down to insert and updates...

Although...

Select statements executed in iBATIS are 10X faster than Hibernate!!!

Why is that??

Maybe the 2.5MB of difference in jar size might be something to do. Hibernate has been trying to reach a broad audience with greater features, but at the end of the day, increasing complexity and code.

I would like to see a proper performance from Hibernate....

I'm finding a good place to post my findings...

Ciao

Posted by Andrea on April 08, 2010 at 01:58 PM MDT #

[Trackback] This post was mentioned on Twitter by mraible: "Select statements executed in iBATIS are 10X faster than Hibernate!!!" http://bit.ly/bqmmTR #hibernate #ibatis #noproofprovided

Posted by uberVU - social comments on April 08, 2010 at 04:03 PM MDT #

@Andrea...

That's some seriously sketchy logic...

iBatis is x mb on disk.
Hibernate is (x+2.5mb) mb on disk.
Therefore, iBatis is 10x faster than Hibernate for select statements.

Huh?

Any diagnostics? Proof? Because your conclusion there is about as valid as if you said "therefore, hamburgers with cheddar cheese on them are 10x better than those with pepperjack."

Posted by Bryan on April 08, 2010 at 07:33 PM MDT #

"Since the first version of Alfresco, Hibernate has been used to provide the object-relational mapping and data access layer against the underlying relational database. Hibernate proved invaluable in enabling us to rapidly build the early versions of Alfresco.

As the size of Alfresco deployments has grown, it's become more important for Alfresco to control the interaction between the application and the underlying database to ensure this is optimized for our use case. In Alfresco 3.4, we have moved away from using the generalized capabilities provided by Hibernate to a native mapping and data access layer developed by Alfresco using Apache iBatis. The new approach provides us with a much greater level of control over the data access layer so we can ensure it continues to scale and support the very large repositories and enterprise deployments that Alfresco is increasingly seeing."

source: http://wiki.alfresco.com/wiki/Alfresco_Community_3.4.a#Hibernate_Removal

Posted by gandra on October 08, 2010 at 02:08 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed