Wednesday, January 17, 2007

Of ActiveRecord/GORM and DAO Patterns

Emmanuel Bernard of the Hibernate team has an interesting post about his dislike for the ActiveRecord pattern which Grails' ORM tech GORM uses. The interesting thing here is that he points to EJB1/2 as an example of the failure of this pattern.

My personal view here is that EJB1/2 failed because it was god awful, not because it used the ActiveRecord pattern. It was configuration heavy, tied you to the technology by being totally obtrusive, and forced you to think about ORM too much. These are the reasons for its failure.

As far as ActiveRecord from Rails and GORM from Grails go the nice thing about these is how remarkable simple they are to use with zero configuration. This is the power and benefit they offer.

Also you can think in an entirely abstract way about the underlying persistence mechanism. For example with GORM at the moment it is backed by Hibernate, but in the future we plan to implement support for JPA and even possibly support for using GORM ontop of Tangasol Coherence or Terracotta so you can use Grails on top of a data grid solution for massively scalable applications.

With GORM not forcing you to extend any base class and being totally unobtrusive this is all possible. The reality is Java frameworks force you to have a DAO layer, its not out of choice that they exist. Still this is not an insurmountable problem, I'm surprised there aren't more AOP based solutions around. In the meantime GORM is solving real problems.

6 comments:

Anonymous said...

Terracotta and data grid support sounds fascinating. It is that kind of functionallity that can be the tipping point for Grails in favour of Rails.

Unknown said...

You write about "the failure of EJB1/2". While I now also dislike EJB2 when compared to ORM mapping tools like JPA/Hibernate, EJB1/2 has not failed. It has been very popular in many enterprise applications. It is being used and it works. It's got issues, yes, but if you look at the history it has not failed. Technology simply develops as time goes...

Bruulstraat 2C, 3360 Lovenjoel said...

If you're going to count the number of occurances to decide if something is popular than paying taxes is very popular.

Seriously, EJB 2 has been frequently used because at the time it was the only offering that offloaded developers from having to deal with transaction management. Second most used feature is message driven beans.

Since all these features are now being offered in much more friendly and more productive ways EJB penetration (not re-iteration) is in sharp decline.

Anonymous said...

I definately agree that for Grails the ActiveRecord pattern as done by GROM is much better and more KISS.

To me it is just more direct and less complex and the main disadvantage not having POJOs goes also away.

What I don't like that much is that GORM is implemented on top of Hibernate. Hibernate is complex and having something on top of it does not make it easier to understand what is realy going on. Maybe a future version of GORM could use a java framework which itself is ActiveRecord based, like carbonado or something similar.

Unknown said...

What about supporting iBatis?

Cameron said...

Graeme - I'll be at JavaOne. If you are around, stop by and say hi, and we could talk about this some more.

Peace.