我有一个关于CF9对象关系映射的问题。
我时不时地得到以下错误(是的,它在大多数情况下都工作得很好),
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'); }
请给我建议。
谢谢!
发布于 2012-12-10 23:52:24
好的,谢谢你们@Henry和@Walter的评论。他们是通向正确解决方案的领头羊。
以下是我为确保它始终稳定所做的工作。
application.mappings"/ormmodel“= expandPath("/root/ormmodel") />
和
this.ormsettings= { cfclocation = "ormmodel",autogenmap = true,...eventhandling="true“};注意cfclocation值中缺少的"/”。
= EntityNew("Pubs");
我希望这将会有所帮助,并为其他人节省数小时的挫折感和悬念。
祝你编码愉快!
发布于 2012-11-30 03:55:24
我也遇到过你的问题,但现在它工作得很好。首先,如果你没有设置ormsettings.cfclocation,ColdFusion会这样做:
如果未设置,ColdFusion将查看应用程序目录、其子目录及其映射目录,以搜索持久性。(参见Spec)
这很容易出错,因为您永远不知道ColdFusion在所有这些目录中找到了什么。
当您将cfclocation添加到您的示例中时,它应该可以工作:
this.ormsettings= {
cfclocation = ["/model", "/other/entities", "/more/other/entites"]
}有很多关于如何为cfclocation指定路径的讨论。对我来说,这种方式是可行的。
但是我的cfclocation的第一个元素总是一个应用程序映射,就像您的this.mappings["/model"]一样。我没有在webroot中使用not服务器别名或CFCs进行测试,也没有进行映射。在拥有"/model“映射时,还应该避免名称空间冲突,比如webroot中的"model”目录。
祝你好运:)
https://stackoverflow.com/questions/13610171
复制相似问题