I read an interesting post the other day titled We should learn from Active Record. While Active Record does help facilitate the quick and dirty, it has a high reliance on the database structure. Your code and database layer essentially one in the same and I’m not sure I like this approach. This is especially true if you’ve had to deal with a crappy database model to begin with.
I’m a fan of type safety and the ActiveRecord approach is a step backward in that regard. The nice thing about Hibernate, and other ORM tools, is that your object model doesn’t have to be a one to one mapping of your database model. In fact, it can be quite different. An single table might map to several different, type-safe objects. Taking Bruce’s
Person example, we may have multiple types of
Address‘s such as
BusinessAddress, ect. Now suppose that you also have a
Company entity which can also have an
Address, but it would need to of type
BusinessAddress. By defining strongly typed objects to represent our business data, we won’t mistakenly pass a
HomeAddess to a
Granted this is a slightly crappy exmaple, I think it kind of gets the point across. If you need a quick and dirty web app up and running quickly, why not just use Ruby on Rails? It’s great for that sort of thing. Do we really need a Java implementation of Active Record?When it comes to planning out a large scale application, I don’t see this sort of RAD approach offering much value long term. The ORM approach abstracts your DB layer from code, so if one layer has to change “it can be” isolated to a degree. But that’s just my opinion.