Coldfusion 9 ORM Mapping问题

时间:2012-11-28 16:47:16

标签: orm coldfusion coldfusion-9 application.cfc

我遇到CF9 ORM映射问题。

我不时会收到以下错误(是的,大部分时间都可以正常运行),

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.

Application.cfc中的ORM定义

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

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

修复它的唯一方法是刷新ORM几次,即在Application.cfc上点击?init = true。它仍然是一个临时解决方案,但我需要知道它的根本原因并修复它。

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

请告知。

谢谢!

2 个答案:

答案 0 :(得分:1)

我也有你的问题,但现在它运作正常。首先,如果你没有设置ormsettings.cfclocation,ColdFusion会这样做:

  

如果未设置,ColdFusion将查看应用程序目录及其子目录及其映射目录,以搜索持久性CFC。 (见Spec

这很容易出错,因为你永远不知道ColdFusion在所有目录中找到了什么。

在您的示例中添加cfclocation时,它应该可以工作:

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

关于如何指定cfclocation的路径,有很多讨论。对我来说,这种方式有效。

但我的cfclocation的第一个元素始终是应用程序映射,就像您的this.mappings["/model"]一样。我没有在webroot中使用Web服务器别名或CFC进行测试,没有映射。您还应该避免与webroot中的“​​模型”目录发生冲突,同时具有“/ model”映射。

祝你好运:)

答案 1 :(得分:1)

好的,谢谢你@Henry和@Walter的意见。他们是正确解决方案的主角。

这就是我所做的,以确保它始终稳定。

  1. 我为所有ORM CFC使用了一个文件夹(位置)。以前每个部分都有一个“模型”文件夹。 Sections是一个根目录下的兄弟文件夹,并共享相同的Application.cfc。 我将其更改为所有CFC的ONE根级文件夹,即:/ root / ormmodel
  2. 在/root/Application.cfc上,我调整了以下代码

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

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

    注意cfclocation值中缺少“/”。

  3. 在调用模型组件时,我将代码从pub = new ormmodel.Pubs()更改为

    pub = EntityNew("Pubs");
    
  4. 在一个不相关的问题上,我已将组件名称更改为camelCase命名,并避免使用下划线和短划线等特殊字符。

  5. 我希望这会有所帮助,并为其他人节省数小时的挫折和悬念。

    快乐的编码!

相关问题