Tuesday, December 12, 2006

Why I truly, honestly dislike Hibernate


It was such a promise and of course such a letdown. Model driven approach, forward engineer your Java classes, have Hibernate persist them to rdbms behind the scenes. It was the single greatest risk of the project.

First it took ages to incorporate into the generator some of the history and many to many options. Straightforward dog house style classes are easy, the rest requires serious investing in time. So we lost a quarter on that, trying to get it right - and not the smallest minds, but a combination of dbms aces and math majors.

Then - we could not delete objects. Just. Could not delete. Some spooky discord between lazy instantiation and session handling. Some things were not committed. Some things were not really multiuser, and the system balked at having two people working at the same time on an admin screen.

We had it investigated, some of those very highly paid highly focused nerds. It came out our session handling was 'all wrong.' Where you normally, the last 20 years I am in rdbms at least, open a session, have transactions and close it (or have it closed by the OS) when you are done, this thing refused to commit. And had a singleton session object, that forgot about your work when someone else used it. Brrr. So we had a very traumatic rewrite of session handling - ah yes, and the consultant deemed Hibernate2 so bad that we had to fall forward to Hibernate3.

The rewrite literally yielded hundreds of bugs. Simple select from things failed, and the session.iterate calls from their own Hibernate2 manuals were deprecated - it was laughable to use them, they did a select for every row. Presented in a way like we were stupid, only, we were not, because it was all in their own samples and nobody told us about the depth of this stupidity - in their own docs.

Now switched to a default of all lazy instantiation (and yes, the statements from a moderately deep inheritance hierarchy already ran out of DB2's JDBC statement buffer), we had to change SQL Query syntax to very unnatural select from StaffMember left join fetch HisName left join fetch HerSocialSecurityNumber etc. Otherwise you get Null Pointers.

So they managed to change query semantics so that everybody that knows his SQL is a total beginner again and has to adapt to funny quirks. So enough. Out with it. It is the emperors new clothes. Let it sleep.

Now the sad part of it is that in the years before this happened, we had written our own O/R layer, that, erm ... just worked. It was people that did not trust this beautiful small piece of technology that suggested using Hibernate for the big, important project. We thought by giving in, they would help us building the system. They did not. Darn them to Heck. Let them forever Hibernate.

2 comments:

Zaaf said...

Some nice thoughts about OR-mappers can be found both <http://plasmasturm.org/log/435/> and in links in that article.

Zaaf said...

Oh, and what about the things said in <http://lesscode.org/2005/07/15/more-j2ee-vs-rails/>?

It really nails down the state of the art in java with regards to ORM vs the state of the art in Ruby (on rails?).