【问题标题】:ColdFusion ORM mappedSuperClass .hbmxml has too many fieldsColdFusion ORM mappedSuperClass .hbmxml 的字段太多
【发布时间】:2014-11-24 09:33:23
【问题描述】:

当我运行下面的代码时,ColdFusion 9(更新到最新版本)为 billingaddress cfc 生成了一个错误的(恕我直言)XML 文件。即,它包括base.cfc 的属性。这是一个错误,是我遗漏了什么,还是这是预期的行为?

Application.cfc

component
{
  this.name = "ormtest";
  this.mappings["/model"] = expandPath( "./model" );
  this.datasource = "mingo";
  this.ormEnabled = true;
  this.ormSettings = {
    CFCLocation = "/model",
    dbcreate = "dropcreate",
    savemapping = true
  };

  function onRequestStart()
  {
    ormreload();    
  }
}

base.cfc

component mappedSuperClass = "true"
{
  property fieldType = "id"     name = "id" generator = "guid";
  property fieldType = "column" name = "deleted" ORMType = "boolean" default = "0" notnull = "true";
  property fieldType = "column" name = "sortorder" ORMType = "integer";
  property fieldType = "column" name = "label";
}

地址.cfc

component extends = "model.base"
          persistent = "true"
          table="address"
          discriminatorColumn = "discriminator"
{
  property name = "address";
}

帐单地址.cfc

component extends = "model.address"
          persistent = "true"
          table="address"
          discriminatorValue = "billingaddress"
{}

帐单地址.hbmxml

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <subclass discriminator-value="billingaddress"
        entity-name="billingaddress" extends="cfc:model.address"
        lazy="true" name="cfc:model.billingaddress">
        <property name="deleted" type="boolean">
            <column name="deleted" not-null="true"/>
        </property>
        <property name="sortorder" type="integer">
            <column name="sortorder"/>
        </property>
        <property name="label" type="string">
            <column name="label"/>
        </property>
    </subclass>
</hibernate-mapping>

【问题讨论】:

  • 你有 dbcreate = "dropcreate" 和 savemapping = true 的任何原因?在你的 onRequestStart() 中还有一个 ormreload() 将导致你的模型在每个请求上都被重建。将它放在 onApplicationStart() 中更正常。
  • 是的,原因是,这只是一个测试设置,以验证我的理智。在实时和开发环境中,我们使用不同的设置运行(dbcreate="none" for live)

标签: hibernate orm coldfusion coldfusion-9


【解决方案1】:

这是我所期望的行为。扩展组件将导致子组件继承父组件的属性。当您有多个级别的继承时,它将一直沿链继承。

在阅读了您的 cmets 之后,我对此进行了更深入的研究。据我所知,您所描述的问题首先出现在 CF9 Cumulative Hot Fix 2 中,可能(只是在这里猜测)是此错误修复的结果:

ColdFusion ORM 无法正确维护列顺序 CFC 扩展了一个基础 cfc,其属性 mappedSuperclass 设置为 真的。

引用的错误是 #83474,我似乎在 Adob​​e 的错误跟踪器上找不到它。它反映在 Elliot Sprehn 的网站上,here

我还在这里找到了关于同一问题的另一个问题:Wrong HBM mappings when using a mapped superclass in an inheritance graph for ColdFusion 9.0.1 Hotfix 2。该问题中报告的解决方法是手动编辑 hbmxml 文件。

长话短说,它看起来像一个 CF 错误。我戳了它大约 20 分钟,除了手动编辑 hbmxml 文件以从 billingaddress.cfc 中删除额外的属性之外,找不到解决方法。

【讨论】:

  • 你知道我应该如何在使用 mappedSuperClass="true" 时重新创建这个 strategy 吗?因为当我这样做时,休眠返回一个重复的列错误:Repeated column in mapping for entity: billingaddress column: deleted (should be mapped with insert="false" update="false") 这是有道理的。我很好奇为什么它会知道它需要继承“id”列而不是其他列。
  • 这似乎是 CF9 的一个错误,我已经在 Railo 4.2 中测试了相同的代码,并且它可以按预期工作。
  • 大约一个小时后,我可以在 CF11 上试一试。我没有安装任何早期版本。
  • 感谢您的帮助,我已经接受了您的回答,并将使用手动 hbmxml 文件,至少现在是这样。
  • 我找到了这个bug的bugbase link,但是它被标记为Fixed。
猜你喜欢
  • 2012-07-31
  • 2010-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-06
  • 1970-01-01
  • 2012-03-14
  • 1970-01-01
相关资源
最近更新 更多