Pergunta

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!

Foi útil?

Solução 2

Okay, thank you both @Henry and @Walter for your comments. They were the lead toward the right solution.

Here's what I did to make sure it's stable ALL the time.

  1. I used one folder (location) for all ORM CFCs. There used to be a "model" folder for each section. Sections are sibling folders under one root and share the same Application.cfc. I changed that to ONE root level folder for all CFCs, ie: /root/ormmodel
  2. On the /root/Application.cfc, I adjusted the following code

    <cfset application.mappings["/ormmodel"] = expandPath("/root/ormmodel") />
    

    and

    this.ormsettings= {
        cfclocation = ["ormmodel"],
        autogenmap = true,
        ...
        eventhandling="true"                            
    };  
    

    Notice the missing "/" in the cfclocation value.

  3. On calling for model components, I changed the code from pub = new ormmodel.Pubs() to

    pub = EntityNew("Pubs");
    
  4. On an unrelated point, I've changed my components name to camelCase naming and avoided special characters like underscores and dashes.

I hope this would be helpful and save someone else hours of frustration and suspense.

Happy coding!

Outras dicas

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:)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top