Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion 9 ORM Mapping issue

I have an issue with CF9 ORM mapping.

I get the following error from time to time (yes, it works fine most of the time),

Mapping for component model.Pubs not found. Either the mapping for this component is missing or the application must be restarted to generate the mapping.

ORM definition in Application.cfc

    <cfscript>
    this.datasource = "Pubs";
    this.ormenabled = true;
    this.ormsettings= {
                        dialect="MicrosoftSQLServer",
                        dbcreate="update",                              
                        eventhandling="true"
                    };      
</cfscript>

<cfset this.mappings["/model"] = getDirectoryFromPath(getCurrentTemplatePath()) & "model" />

The only way to fix it is to refresh the ORM couple of time, which is by hitting ?init=true on Application.cfc. It is still a temporary solution, but I need to know the root cause of it and fix it.

<cfscript>          
if(structKeyExists(url, "init")) { ormReload(); applicationStop(); location('index.cfm?reloaded=true'); }

Please advise.

Thanks!

like image 457
John N Avatar asked Nov 03 '22 10:11

John N


1 Answers

I also had your problem, but now it works fine. First, if you don't set ormsettings.cfclocation, ColdFusion does this:

If it is not set, ColdFusion looks at the application directory, its sub-directories, and its mapped directories to search for persistent CFCs. (see Spec)

This is error prone, because you never know what ColdFusion finds in all that directories.

When you add cfclocation to your example it should work:

this.ormsettings= {
    cfclocation = ["/model", "/other/entities", "/more/other/entites"]
}

There is a lot of discussion out there, about how to specify the paths for cfclocation. For me, that way works.

But the first element of my cfclocation is always an application mapping, like your this.mappings["/model"]. I have not tested it with webserver aliases or CFCs in the webroot, without mapping. You should also avoid colliding namespaces, like a "model" directory in the webroot, while having a "/model" mapping.

Good luck:)

like image 145
Walter Seethaler Avatar answered Nov 09 '22 06:11

Walter Seethaler