I'm tinkering with a little project and having moved my blog to HostmediaUK I've decided to have more of a play with ColdFusion 9 features.
I've looked at ColdFusion 9's ORM stuff a couple of times, but I've never actually used it properly, so I thought I'd write the database access functionality using ORM.
- Create a couple of CFCs for my datatypes.
- Tell the Application CFC that the application is ORMEnabled.
- Tell ColdFusion to generate my database tables
- Add some data
- Save my object
Job done... ummm no.
"Error Occurred While Processing Request Could not find the ColdFusion component or interface user"
In Application.cfc I have :
this.ormsettings.dialect = "MySQLwithMyISAM";
this.ormsettings.logSQL = true;
this.ormsettings.cfclocation = "/com/nil/orm";
In my application page I have :
user = new user();
Why can't I find my "user" component? I changed my code to user = EntityLoad("user"). Now I'm getting method not found.
I go through a bunch of iterations based around this and even get a "Mapping for component user not found" error before I start to talk through my rubbish code with John Whish.
There were two things I was doing wrong.
The first thing is that I should be using EntityNew() not EntityLoad(). I've got so used to Transfer-ORM and just getting a data object ie. Loading it whether I want a new or an existing data record.
Secondly, the reason why user = new user(); doesn't work is because its looking for my component in the root path. My user cfc actually lives in /com/nil/orm as I specified in my Application.cfc.
The entity functions such as EntityNew() and EntityLoad() work using simple names because Hibernate basically creates a "bean factory" of the data components. When I do EntityNew("user") it looks in the pot for a component of the same name and uses that.
If I want to use the "new user()" style of instantiation I have to give the full path to the component.
user = new com.nil.orm.user();
Its a silly error that I'm entirely embarrassed about making, but its important distinction that might be missed when you first start out playing with ColdFusion's ORM features.
By the way, the "Mapping for component not found" error was caused by moving the user.cfc to the root of my application and then calling EntityLoad("user"). Hibernate was looking in my cfc location and couldn't find the "user" component.