ColdFusion ORM 关系映射“一对多”映射到子类时出现问题

发布于 2024-11-30 02:46:52 字数 1760 浏览 0 评论 0原文

这是可重复的,并且可能是一个错误。对于此示例,我有三个表:

付款
付款ID
日期
付款类型

信用
付款ID
卡号
卡类型ID

卡类型
身份证号
描述

Payment 和 Credit 分别是父类表和子类表。代码如下:

payment.cfc

component persistent="true" table="payment" discriminatorcolumn="paymentType"{
    property name="paymentID";  
    property name="date";
}  

credit.cfc

component persistent="true" extends="payment" joincolumn="paymentID"  
    table="credit" discriminatorvalue="ccard"{
    property name="cardNo";  
    property name="cardTypes" fieldtype="many-to-one" lazy="true" cfc="cardType"
        fkcolumn="cardTypeID";
}  

cardType.cfc

component persistent="true" table="cardType"{
    property name="id";
    property name="description";
    property name="creditCards" fieldtype="one-to-many" lazy="extra" 
        type="struct" structkeycolumn="id" cfc="credit" fkcolumn="cardType";
}  

错误在于“一对多”关系关闭卡类型.cfc。当ORM生成SQL时,它会尝试将fkcolumn应用于父类的select和where子句:

select
    creditcard0_.cardType as cardType30569_1_,
    creditcard0_.PaymentID as PaymentID1_,
    creditcard0_.PaymentID as PaymentID30570_0_,
    creditcard0_.Date as Date30570_0_,
    creditcard0_1_.cardNo as cardNo30572_0_,
    creditcard0_1_.cardType as cardType30572_0_ 
from
    Payment creditcard0_ 
inner join
    CreditCardPayment creditcard0_1_ 
      on creditcard0_.PaymentID=creditcard0_1_.PaymentID 
where
    creditcard0_.cardType=?  

这会在调用简单的entityload(“cardType”)时导致大量“CardType不存在”错误。

任何人都知道为什么它不能正确地将其应用到子类,这是否可能是我缺少的配置设置。

提前致谢。

This is repeatable and may be a bug. For this example I have three tables:

Payment
paymentID
date
paymentType

Credit
paymentID
cardNo
cardTypeID

CardType
ID
Description

Payment and Credit are parent and subclass tables respectively. The code is as follows:

payment.cfc

component persistent="true" table="payment" discriminatorcolumn="paymentType"{
    property name="paymentID";  
    property name="date";
}  

credit.cfc

component persistent="true" extends="payment" joincolumn="paymentID"  
    table="credit" discriminatorvalue="ccard"{
    property name="cardNo";  
    property name="cardTypes" fieldtype="many-to-one" lazy="true" cfc="cardType"
        fkcolumn="cardTypeID";
}  

cardType.cfc

component persistent="true" table="cardType"{
    property name="id";
    property name="description";
    property name="creditCards" fieldtype="one-to-many" lazy="extra" 
        type="struct" structkeycolumn="id" cfc="credit" fkcolumn="cardType";
}  

The error lay with the "one-to-many" relationship off of cardType.cfc. When ORM generates the SQL, it tries to apply the fkcolumn to the select and where clauses to the parent class:

select
    creditcard0_.cardType as cardType30569_1_,
    creditcard0_.PaymentID as PaymentID1_,
    creditcard0_.PaymentID as PaymentID30570_0_,
    creditcard0_.Date as Date30570_0_,
    creditcard0_1_.cardNo as cardNo30572_0_,
    creditcard0_1_.cardType as cardType30572_0_ 
from
    Payment creditcard0_ 
inner join
    CreditCardPayment creditcard0_1_ 
      on creditcard0_.PaymentID=creditcard0_1_.PaymentID 
where
    creditcard0_.cardType=?  

This causes a lot of "CardType does not exist" errors when a simple entityload("cardType") is called.

Anyone have any idea why it would not apply it correctly to the child class and is it possibly a configuration setting I am missing.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦萦几度 2024-12-07 02:46:52

因此,如果我像这样映射 hbmxml 文件,显然它可以解决问题:

<map lazy="extra" name="creditCards" table="CreditCardPayment" inverse="true">
    <key column="cardType"/>
    <map-key column="CardNo" type="string"/>
    <many-to-many unique="true" column="PaymentID" class="cfc:entities.credit"/>
</map>

So, If I map the hbmxml file like so, apparently it fixes the issue:

<map lazy="extra" name="creditCards" table="CreditCardPayment" inverse="true">
    <key column="cardType"/>
    <map-key column="CardNo" type="string"/>
    <many-to-many unique="true" column="PaymentID" class="cfc:entities.credit"/>
</map>
故人如初 2024-12-07 02:46:52

尝试将mapedSuperClass="true" 添加到付款CFC。不确定这是否可以正常工作,因为我通常对非持久“基础”对象使用mappedSuperClass。

Try adding mapedSuperClass="true" to the Payment CFC. Not sure if this will work as typically I have used mappedSuperClass for non persistent 'base' objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文