I've been doing some experimentation with ColdFusion 9's Hibernate (ORM) integration, part of which involved creating a Base Persistent Object.
What is a Base Persistent Object?
I'm using the term persistent object to refer to a ColdFusion 9 cfc that has a persistent="true" attribute. That is, a component that is used to create objects that will be persisted to a database via Hibernate, using CF9's ORM integration. These are variously referred to as persistent objects, ORM objects, entity objects, etc. There are certain behaviours that I want all of my persistent objects to have, and I have found that the best way to achieve this is to create a base persistent object and then have all of my concrete persistent objects extend that base object.
Behaviours contained in the Base Persistent Object
The behaviours that I'm including in my Base Persistent Object allow any object that extends it to:
- populate itself from user-submitted data
- save itself
- delete itself
- validate itself
- inject dependencies into itself via Coldspring
As CF9 is still in beta, this object is obviously in flux. I am planning on releasing the code for the object as open source, and have set up a project at BasePersistentObject.riaforge.org for that purpose. I hope to have a 0.1 version available shortly, at which point the code will be available for download via the project page.