Issues with the ActiveRecord Pattern and Statically Typed Languages

| by Scott Delap on Jan 17, 2007. Estimated reading time: less than one minute |
Hibernate team member Emmanuel Bernard recently wrote on the issues with the ActiveRecord pattern and statically typed languages like Java. He states that:
...Dynamic languages (and to a certain extend AOP) have the nice ability to decorate an object with additional features on the fly, without linking it "the hard way": you can then easily reuse your domain classes out of the persistence context...

Bernard goes on to say that this lack of ability with statically typed languages has given rise to DAO (DAL in .Net land) patterns to separate data representation and persistence technology. The solution to this in the statically typed world in his opinion is dynamic DAO generation which is already being done in JBoss Seam from generics and GORM in Grails.

Grails project lead Graeme Rocher adds:

...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...

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

AOP injection of DAO into domain object by Gerald Loeffler

Regarding the statement "I'm surprised there aren't more AOP based solutions". Well, some time ago the combination of Spring 2.0 and AspectJ offered the ability to inject DAO objects into domain objects so that the domain objects are not so "anemic" any more (see this blog entry, for instance).

I personally can live quite well with the situation that business logic that requires the persistence API lives in the DAO, while other business logic is defined in the domain object itself. But of course it creates an unnatural divide for the client of that business logic. The above AOP-based injection of the DAO into the domain object makes that divide almost invisible to the client - and all that from an old-fashioned statically typed language ;-)


Static Typing by Jonathan Locke

The existence of a static type hierarchy does not necessarily preclude flexible type combinations or runtime decorations. What it does do is give you the ability to scale complexity safely. It's great that we're rediscovering dynamic languages even if it is for the umpteenth time, but what we're ultimately going to need for complex projects that need to be reliable is a combination of type checking, type combining and type dynamism. There are a lot of unaddressed issues, but I'd really like to see that start in the general neighborhood of my Type Enhancers proposal linked above.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss