Tuesday, June 21, 2005

Hibernate is evil

Hi, I'm Kim (Hi, Kim) and I don't like Hibernate. (gasps from the crowd)

Yes, it's true. I will come forward and admit it. I don't like Hibernate.

I was just chalking up my distaste to learning curve, etc., but every time I try to do something not totally simple with Hibernate it takes forever to figure out, then I'm not happy with what it ends up actually doing. I finally realized that I just don't like it. Based one what "everybody else is doing", it seemed like I _had_ to like it. But I rarely go with the crowd, so why start now?

Hibernate is for people who are afraid of SQL. Legend has it that my predecessor at my current job didn't know how to write a simple SQL join and apparently loved Hibernate. There are times when you should let the database do what it does best. Hibernate greatly complicates that goal. Recently, I was trying to do some optimization to an inherited system. My SQL-fearing predecessor had implemented a "search" feature by first selecting all records from multiple tables, then used java code to loop the objects multiple times looking for matches on String values. I wanted to fix this so the database only returned the rows that actually mattered.

What would've taken me about an hour with plain-old JDBC and object mapping by hand
took who knows how long with Hibernate. I worked on it for about a day and a half, then had to stop because our funding was temporarily cut on that project. We have funding back and I have a meeting this afternoon to discuss scheduling. How in the world do I estimate this monster? I may just re-implement that piece without Hibernate and save myself the headaches.

What have I found that makes the world right again? IBatis. (Thanks, Gary!)IBatis is great because it lets the database do what it does best, then does the results to object mapping for you. You put some plain-old SQL in XML config files, then add some mapping info so it knows what objects to use for getting and setting data. It even has a very cool dynamic SQL builder that's helpful for things like search screens.

What does it not have that Hibernate does? Oh, I don't know. Maybe just that it doesn't "know" what has been updated locally, but not persisted. I can handle that if it makes my life this much easier. Overall, it just makes a hell of a lot more sense than Hibernate and it feels like there's less "magic". I feel better feeling like I understand what's actually going on. Plus, I've always liked SQL.


Post a Comment

<< Home