Wednesday, April 7, 2010

Hibernate sucks

I am so frustrated using Hibernate. Spring JDBC is so much easier and it actually WORKS! In Hibernate, a simple OneToMany relationship does not work. I have a simple parent child relationship. Say a box which can contain other boxes. If i try to load all the boxes which do not contain other boxes, i get a List of Box Objects which duplicate entries because it is returning a row for each contained box.

To work around this bug, which no one on the Hibernate forums even will respond to my request for help, i have to set the children to load lazily then manually iterate over the parent boxes to load the children. How stupid.

The next bit of fun was moving a object out of a Collection on one Object to another. What is a simple SQL statement turned into a two day Google and hacking to make work right.

This is in addition to having to work around with all the proprietary mappings and HQL nonsense. Why use this stuff when SQL exists, is very simple to use, and extremely robust? In the end, you write your "complex" queries yourself via the mentioned proprietary HQL or even gasp...SQL from Hibernate.

If i did not need Hibernate Search on this project i would ditch Hibernate in a second in favor of Spring JDBC.

2 comments:

Anonymous said...

So very true. It complicates the living shit out of things while also introducing a ton of additional complexity.

Anonymous said...

HibernAIDS is one of the worst things that can infect your DAO layer or your RBMS itself. There is a cure called refactoring that implies using your brain and SQL.

Remember the days when the only thing everyone grokked were the SQL queries? No problems with that. Ok, database design is a bit more sophisticated..

But now we have hibernate and what have we got?

Complexity without features == productivity loss