ColdFusion 9's new Object-Relational Mapping (ORM) functionality seems very awesome. I've been trying to really get into it, a feature at a time, and I think I've only begun to scratch the surface. As I've been learning about it, however, I wonder if I have started to lose sight of some of the bigger picture. What is ORM and how much should our ColdFusion applications know about it?
First, let's think briefly about our application architecture. Typically, we have three layers (at least that's what we're shooting for): our Model, our Controller, and our Views. We all know what MVC (Model-View-Controller) is at this point, so I won't expand on that. Then, we have this sort of pseudo layer in there for data persistence. This data persistence layer is generally created as part of the Model such that we don't have to start writing queries directly in the Controller or the Views.
Ok, so where does ORM fit into this architecture? Clearly, it's part of the data persistence layer, as that is quite literally what it does. But, I think the big question becomes: Is it the data persistence layer, or is just part of the data persistence layer?
I don't think it makes sense for ORM to compose the entirety of the data persistence layer as that creates unnecessary constraints. As such, I think it only makes sense for the ORM functionality to be a sub-set of the data persistence layer. If that is the case, though, I think it then follows that the Controller would never access ColdFusion 9's Entity***() methods directly. Rather, those Entity***() methods should probably be encapsulated inside cohesive service objects such that the greater application can access the data persistence layer without having to know more than is necessary about the underlying implementation.
So, I guess, what I'm saying / theorizing, is that the ORM functionality should be thought of more as a "database implementation" rather than a piece of functionality that can be called from anywhere.
ORM is very new to me, so maybe I'm waaaaay off here. Thoughts on this?