ColdFusion ORM 关系映射“一对多”映射到子类时出现问题
这是可重复的,并且可能是一个错误。对于此示例,我有三个表:
付款
付款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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,如果我像这样映射 hbmxml 文件,显然它可以解决问题:
So, If I map the hbmxml file like so, apparently it fixes the issue:
尝试将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.