October 02, 2004

Hibernate on the brink...

As I have said many times before, Hibernate is not my favorite persistence framework. But we decided to use Hibernate at work because my opinion was pretty biased and there were books available for Hibernate.

So, I have been using Hibernate for the last two weeks and I have decided that I still don't like it. There are tools that allow you to generate your POJO's, but they don't create your DAO's. There are tools that will create your tables for you, but how often do you need to do that? This is actually one of the areas where Jaxor is lacking. The problem isn't that Jaxor can not create your tables for you, because it currently creates tables in HSQLDB for unit testing, the problem is that Jaxor doesn't do this in a production like way.

Jaxor also doesn't have a default way of setting the primary key. There is a suggested way that is covered in the questions, but Jaxor doesn't come with that built in.

Even though Jaxor doesn't have all of these things, Hibernate does not have DAO's. Granted, the DAO's are made up of one or two line methods (if you are using Spring) but I still have to write them and the service layer. After I generate my domain layer with Jaxor, all I have to provide is the service layer. For a while I thought that I was doing this incorrectly because I didn't have as many layers as the properly architected applications, but I am actually doing it right. Jaxor just provides so much more functionality that I only have to focus on what parts need to be glued together to make the business work. I am pretty sure that means Jaxor is a better product.

Because I thought I wasn't architecting the system properly, I was reluctant to push Jaxor as hard as I could. I gave in pretty easy and now I am starting to think that was a mistake. My team is not going to like me all that much on Monday if I decide we should switch, but I am starting to think we should. I want to do some testing to find out how Jaxor and Spring interact, but I have a feeling that after this weekend, we will be using Jaxor instead of Hibernate.

Posted by carl at October 2, 2004 12:10 AM

Comments

FWIW, I prefer to avoid them because they add no functionality and take development time that could be spent elsewhere. That said, there are times when you need them, and I see why you want to generate them.

Depending on your architecture, Hibernate gives you some ways to eliminate DAOs, and use your POJOs instead. If you're building a web application, you may be able to use open session in view. (http://hibernate.org/43.html)

If that doesn't work, you might try disconnecting the POJO's session. This allows you to use the objects, so long as you don't do anything that might trigger database activity.

Posted by: Alan Green at October 2, 2004 10:51 PM